Download presentation
Presentation is loading. Please wait.
Published byHarvey Summers Modified over 5 years ago
1
Queues Model Operations Pointer Implementations Array Implementation
Stacks and Recursive Procedures 4/21/2019 CS 303 – Queues Lecture 6
2
ADT Queue - Model Specialization of List FIFO: First In, First Out
Insert at End Delete at Front 4/21/2019 CS 303 – Queues Lecture 6
3
Queue - Operations MakeNull(Q) // MakeNull(L)
T/F = Empty(Q) // First(L) == End(L) Enqueue(Q,x) // Insert(L,End(L),x) x = Front(Q) // Retrieve(L,First(L)) Dequeue(Q) // Delete(L,First(L)) [Variation: x = Dequeue(Q) Exercise: work out details] x: ElementType S: StackType L: ListType Any List Implementation will do, but can we do better? 4/21/2019 CS 303 – Queues Lecture 6
4
Pointer Implementations – First Attempts
Doubly Linked List? [Overkill] Q a1 a2 an Singly Linked List? [no Header, but still pointer overhead] Dequeue is EASY, but Enqueue is HARD Q a1 a2 a3 ... an 4/21/2019 CS 303 – Queues Lecture 6
5
A better Pointer Implementation
Q a1 a2 a3 ... an Enqueue and Dequeue are both EASY 4/21/2019 CS 303 – Queues Lecture 6
6
Array Implementation Circular Array, with zero-based indexing
i i+1 i+n-1 MaxLength-1 a1 a2 an Front Rear Circular Array, with zero-based indexing Full/Empty conditions are tricky! Leave empty buffer region to avoid bugs and simplify code. 4/21/2019 CS 303 – Queues Lecture 6
7
Stacks and Recursive Procedures
Recursion is implemented (by the System) by Pushing state onto a Stack Even when this is provided automatically, you must Analyze as if the stack were explicit. Sometimes it is useful to manage the stack explicitly Usually better to write recursive routines and let the System do it Manual elimination of tail recursion considered harmful! All bets are off in primitive environments. 4/21/2019 CS 303 – Queues Lecture 6
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.