L4b_-_Queue_ADT_(4_on_1) - Lecture Outline Lecture 4b Queue...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 4b Queue ADT 2 --- 31 [CS1102C AY0708S1 Lecture 4b] Lecture Outline ± Queue ² Introduction ² Specification ² Implementations ± Linked List Based ± Array Based ² Application ± Palindrome checking 3 --- 31 [CS1102C AY0708S1 Lecture 4b] What is a queue ± Real life example: ² A queue for movie tickets, Airline reservation queue, etc ± First item added will be the first item to be removed ² Has the F irst I n F irst O ut (FIFO) property ± Major Operations: ² Enqueue: Items are added to the back of the queue ² Dequeue: Items are removed from the front of the queue ² Get Front: Take a look at the first item 4 --- 31 [CS1102C AY0708S1 Lecture 4b] Queue: Illustration A queue of 3 persons Enqueue a new person to the back of the queue Dequeue a person from the front of the queue
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
5 --- 31 [CS1102C AY0708S1 Lecture 4b] Queue ADT (Linked List) : C++ Specification #include “QueueException.h” template<typename T> class Queue { public: Queue(); bool isEmpty() const; int size() const; void enqueue(const T& newItem) throw (QueueException); void dequeue() throw (QueueException); void dequeue(T& queueFront) throw (QueueException); void getFront(T& queueTop) const throw (QueueException); private: //Implementation dependant //See subsequent implementation slides }; 6 --- 31 [CS1102C AY0708S1 Lecture 4b] Queue ADT : Implementations … ± Can we make use of List ADT? ² Efficiency of Array based List ADT (Lecture 3b Slide 18): ± Removing item at the head is the worst case ± Adding item at the back is the best case ² Efficiency of singly linked list based List ADT (Tutorial 2 Question 4): ± Removing item at the head is the best case ± Adding item at the back is the worst case ± Is it possible to have both efficient enqueue() and dequeue() operations? Queue ADT using Modified Linked List 8 --- 31 [CS1102C AY0708S1 Lecture 4b] Improving the Singly Linked List ± The singly linked list used by List ADT performs badly for enqueue() ² Need to traverse all the way to the last node ²
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/02/2009 for the course ECE CS1102C taught by Professor Dr.tansuntuck during the Spring '07 term at National University of Singapore.

Page1 / 8

L4b_-_Queue_ADT_(4_on_1) - Lecture Outline Lecture 4b Queue...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online