Professional Documents
Culture Documents
Data S
Data S
Data S
• Like arrays
An Algorithm
• empty() : Boolean
• Tests if this stack is empty.
• peek () : E
• Looks at the object at the top of this stack without removing it from the stack.
• pop : E
• Removes the object at the top of this stack and returns that object as the
value of this function.
• push (E item) : E
• Pushes an item onto the top of this stack.
• Search (Object o) : Object
• Returns the 1-based position where an object is on this stack from the top.
Uses of the stack
• add (E e) : Boolean
• Inserts the specified element into this queue if it is possible
• returning true upon success and throwing an IllegalStateException if no space is
currently available.
• element(): E
• Retrieves, but does not remove, the head of this queue.
• Will return an expectation if the queue is empty
• offer (E e) : Boolean
• Inserts the specified element into this queue if it is possible
• Return true of or false
• peek ()
• Retrieves, but does not remove, the head of this queue, or returns null if this
queue is empty.
Queue methods
• poll(): E
• Retrieves and removes the head of this queue or returns null if this queue is
empty.
• remove()
• Retrieves and removes the head of this queue.
• Will return an expectation if the queue is empty
Uses of the queues
• Keyboard buffer (making the letters appear in the order they were
inserted in)
• Printer queue
• Used in linkedLists, PriortyQeueus, Breadth-first search
Priority Queue
• Upon entering the elements, the priority queue will arrange them