Stacks and Queues. Not really data structures – More of an enforcement of policy – Can be implemented using an array or linked list – Can store just about.

Similar presentations

Presentation on theme: "Stacks and Queues. Not really data structures – More of an enforcement of policy – Can be implemented using an array or linked list – Can store just about."— Presentation transcript:

2
Not really data structures – More of an enforcement of policy – Can be implemented using an array or linked list – Can store just about any kind of data Queues – First In, First Out (FIFO) – Like waiting in line Stacks – First In, Last Out (FILO) – Like a stack of trays Stacks and Queues

3
Stacks Three primary operations – Push() – put new data on the top of the stack – Pop() – remove data from the top of the stack – Peek() – get a copy of the data on the top of the stack Useful – our function stack! – stack of cards, tiles, loot, etc…

16
Queues Two primary operations – Enqueue() – put new data at the end of the queue – Dequeue() – remove data from the beginning of the queue – Peek() – yes, its still there… Useful – Enforcing fairness (waitlist at SPSU) – Player turns during a round

28
Not really data structures – More of an enforcement of policy – Can be implemented using an array or linked list Queues are FIFO Stacks are FILO Which data structure is LILO? Which one is LIFO? Summary