Presentation is loading. Please wait.

Presentation is loading. Please wait.

CISC220 Fall 2009 James Atlas Lecture 11: Queues.

Similar presentations


Presentation on theme: "CISC220 Fall 2009 James Atlas Lecture 11: Queues."— Presentation transcript:

1 CISC220 Fall 2009 James Atlas Lecture 11: Queues

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

3 Queue

4 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?

5 Circular Array

6 Implementing Queue With Circular Array

7 Implementing Queue With Circular Array (2)

8 Implementing Queue With Circular Array (3)

9 Reallocating a Circular Array

10 Deque

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

12 Doubly-linked list

13 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

14 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

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

16

17 Priority Queue ADT front() - returns the highest priority element of the queue without removing it dequeue() - removes (and returns) the highest priority element of the queue queue(x, int) - queues x at the given priority in the queue FIFO structure??

18 Brainstorm Come up with several ways to use our LinkedList to implement a Priority Queue Record the order of operations for each ADT function –front() –dequeue() –queue(x, int)

19 Trees Nonlinear data structure


Download ppt "CISC220 Fall 2009 James Atlas Lecture 11: Queues."

Similar presentations


Ads by Google