51 lines
885 B
Plaintext
51 lines
885 B
Plaintext
class FIFO
|
|
declare contents
|
|
|
|
// define constructors for FIFO objects
|
|
def FIFO()
|
|
this.contents = {}
|
|
end
|
|
def FIFO(contents)
|
|
this.contents = contents
|
|
end
|
|
|
|
// define methods for this class
|
|
def push(value)
|
|
contents.append(value)
|
|
end
|
|
def pop()
|
|
if !this.empty()
|
|
value = contents[len(contents) - 1]
|
|
contents.remove(len(contents) - 1)
|
|
return value
|
|
else
|
|
// we could throw our own exception here but
|
|
// we'll return null instead
|
|
return null
|
|
end
|
|
end
|
|
def length()
|
|
return len(contents)
|
|
end
|
|
def extend(itemlist)
|
|
contents += itemlist
|
|
end
|
|
def empty()
|
|
return len(contents) = 0
|
|
end
|
|
|
|
// define operators for this class
|
|
def toString()
|
|
return str(contents)
|
|
end
|
|
def operator+(other)
|
|
return this.contents + other.contents
|
|
end
|
|
def operator*(n)
|
|
return this.contents * n
|
|
end
|
|
def operator=(other)
|
|
return this.contents = other.contents
|
|
end
|
|
end
|