10 DS Queue
10 DS Queue
Queues
Topic Structure
• Definition
• Application
• Operation
• Implementation
Bus
Stop
front
rear
• Standard operations:
• addQueue… adds an element to queue’s rear
• deleteQueue… deletes element from queue’s
front and returns it
• isEmpty … returns true iff queue is empty
• Additional operations:
• front… returns the front element of the queue
(without removing it)
• rear… returns the rear element of the queue
(without removing it)
• Using Arrays
– Use a 1D array (static or dynamic), size is fixed
– Elements are added using a front index
– Elements are removed using a rear index
q.deleteQueue()
;
q.addQueue('Z')
;
T * list;
Indicates a default value, i.e.
int maxQueueSize;
int queueFront;
if constructor is not passed
int queueRear; any value, 100 will be used
int count; as value for maxSize
public:
QueueArray(int maxSize = 100)
{ ... }
~QueueArray() { ... }
void addQueue(T elem) { ... }
T deleteQueue() { ... }
bool isEmpty() { ... }
int size() { ... }
};
CT077-3-2-DSTR Data Structures 17
Exercise Solution
~QueueArray() {
delete [] list;
}
bool isEmpty() {
return (count == 0);
}
int size() {
return count;
}
cout << "Add and delete few elements to advance queueRear:" <<
endl;
q.addQueue(1); q.addQueue(2); q.addQueue(3);
cout << q.deleteQueue() << endl;
cout << q.deleteQueue() << endl;
• Definition
• Application
• Operation
• Implementation
• Tree
– Definition and notation
• Binary Tree
– Definition
– Properties
– Representation