Queue/Definition: Difference between revisions

Content added Content deleted
mNo edit summary
Line 3,093: Line 3,093:
dequeue(q); /* 4 */
dequeue(q); /* 4 */
dequeue(q); /* fail */</lang>
dequeue(q); /* fail */</lang>

=={{header|Nanoquery}}==
This is a fully-featured FIFO queue class definition. In addition to the functions required by the task, it also demonstrates redefining operators for Nanoquery classes by redefining +, *, and =.
<lang Nanoquery>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</lang>


=={{header|NetRexx}}==
=={{header|NetRexx}}==