CP114 Lecture 5: Abstract Data Types (ADTs)
Document Summary
Data items are pushed on top of the stack and popped from the top of the stack. The last item added to the stack is always the first item removed from the stack. Push: push a new value onto the top of the stack. Pop: remove and return the value on top of the stack if one exists, otherwise returns null. Peek: return a copy of the value at the top of the stack without removing it, if one exists, throw an error if the stack is empty. Is_empty: returns true if the stack is empty, false otherwise. Length: returns the number of items in the stack. Data items are added to the rear of the queue and removed from the front of the queue. The first item added to the stack is always the first item removed from the stack. Insert: adds a new value to the rear of the queue.