CISC220 Fall 2009 James Atlas Lecture 11: Queues
Objectives for Today Queues Deques Array based implementation Reading - K+W Chap 6
Queue
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?
Circular Array
Implementing Queue With Circular Array
Implementing Queue With Circular Array (2)
Implementing Queue With Circular Array (3)
Reallocating a Circular Array
Deque
Deque ADT back() front() pushBack(x) pushFront(x) popBack() popFront()
Doubly-linked list
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
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
Removal from a Double-Linked List harry->prev->next = harry->next; // Step 1 harry->next->prev = harry->prev; // Step 2 delete harry;
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??
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)
Trees Nonlinear data structure