Presentation is loading. Please wait.

Presentation is loading. Please wait.

CISC220 Spring 2010 James Atlas Lecture 10: Queues.

Similar presentations


Presentation on theme: "CISC220 Spring 2010 James Atlas Lecture 10: Queues."— Presentation transcript:

1 CISC220 Spring 2010 James Atlas Lecture 10: Queues

2 Objectives for Today Stacks Queues Deques Array based implementation Reading - K+W Chap 5, 6

3

4 Stacks

5 Stack ADT peek() - returns the top element of the stack without removing it pop() - removes (and returns) the top element of the stack push(x) - pushes x onto the top of the stack LIFO structure - last in, first out

6 Stack Uses Expression evaluation and syntax parsing –Reverse Polish notation 1 2 + 4 * 3 + Program Execution Stack

7

8 Queue

9 Queue ADT front() - returns the front element of the queue without removing it dequeue() - removes (and returns) the front element of the queue queue(x) - queues x at the end of the queue FIFO structure - first in, first out

10

11 Queue using a LinkedList Multiple Inheritence: class LinkedList : public Collection, public Stack, public Queue front() = first() dequeue() = remove(0) queue(x) = addLast(x) Time complexity?

12

13 Queue using an Array (Vector) Linked lists require extra storage of pointers for next front() = get(0) dequeue() = remove(0) queue(x) = insert(x, length) Time complexity? How can we reduce this?

14 Circular Array

15 Implementing Queue With Circular Array

16 Implementing Queue With Circular Array (2)

17 Implementing Queue With Circular Array (3)

18 Reallocating a Circular Array

19 Deque

20 Deque ADT back() front() pushBack(x) pushFront(x) popBack() popFront()

21 Doubly-linked list

22 Inserting into a Double-Linked List DNode* sharon = new DNode("Sharon"); // Link new DNode to its neighbors sharon->next = sam; // Step 1 sharon->prev = sam->prev; // Step 2

23 Inserting into a Double-Linked List (2) // Link old predicessor of sam to new predicessor. sam->prev->next = sharon; // Step 3 // Link to new predicessor. sam->prev = sharon; // Step 4

24 Removal from a Double-Linked List harry->prev->next = harry->next; // Step 1 harry->next->prev = harry->prev; // Step 2 delete harry;


Download ppt "CISC220 Spring 2010 James Atlas Lecture 10: Queues."

Similar presentations


Ads by Google