Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Add an item to the back of the queue
- # @post: size = old.size+1
- # if !old.empty? then front == old.front
- # if old.empty? then front == item
- # @result: size
- def enter(item)
- if empty?
- @frontNode = @rearNode = Node.new(item,nil)
- else
- @rearNode = @rearNode.next = Node.new(item,nil)
- end
- @count += 1
- end
- # Remove and return the item at the front of the queue
- # @pre: !empty?
- # @post: size == old.size-1
- def leave
- raise UnderflowError, "leave" if empty?
- @count -= 1
- frontItem = @frontNode.item;
- @frontNode = @frontNode.next;
- @rearNode = nil if empty?
- return frontItem
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement