Courses‎ > ‎APCS - Term 1‎ > ‎Konstantinovich‎ > ‎

2019-03-20 Stacks/Queues

posted Mar 20, 2019, 5:43 AM by Konstantinovich Samuel   [ updated Mar 25, 2019, 7:01 AM ]
Goal: How to make Fat Stacks

New topics: Stacks and Queues

Stack operations:
void push(element) - add an element to the stack
element pop() - return the element and remove it from the stack.
element peek()  - return but don't remove the element

Queue operations:
void enqueue(element)
element dequeue()
element peek() 

Double Ended Queue:  (Deque is the java interface and it has many more methods)
void addFirst(element)
element removeFirst()
element getFirst()

void addLast(element)
element removeLast()
element getLast()

int size()
boolean contains(element)


Stack: LIFO
Queue: FIFO
Deque: WhateverO

For stack,queue, and deque:
How could we represent each of them such that all of the above mentioned operations would be constant time?




Comments