Queues

From

Revision as of 20:13, 26 March 2009 by Admin (Talk | contribs)
Jump to: navigation, search

A queue is another basic data structure that is normally homogeneous data. It is similar to a stack except it operates using a FIFO (First In, First Out) ordering. A queue is another way of expressing a line. The standard operations on a queue are enqueue(), dequeue(),
peek(), and isEmpty().

Similar to a stack, a queue can be implemented either by an array or a linked list. When implemented using an array, it is normally implemented as a circular list (circular array). Items are added at the rear and removed from the front—in the same manner as a list. And, just like a list, we need an isFull() operation when using an array.

When using a linked list, items are added to the rear and removed from the front, so we need both front and rear pointers. Also note that similar to a stack, the operations on a queue are constant.

Deque

A deque is a double-ended queue. This means that we can add or remove items from either end. The operations we need are addToFront(), addToBack(), removeFront(), removeBack(), peekFront(), peekBack(), isFull(), sEmpty().

Priority Queue

A priority queue is a standard queue, but the elements have a priority. When an item is entered into the queue, it moves up in the queue until it encounters an item of equal or greater priority. This is its position in the queue.


When implementing a priority queue, it is often implemented as a linked list. If I am adding items to the back of the list, and removing items from the head of the list, a priority queue is best implemented as a doubly linked list. In this case, we would do the following.

Personal tools
MediaWiki Appliance - Powered by TurnKey Linux