Circular queues and implement circular queues using array, Data Structure & Algorithms

Explain what are circular queues? Write down routines required for inserting and deleting elements from a circular queue implemented using arrays.

         Circular queue: Static queues have a very big disadvantage that once the queue is

FULL, even though we delete or remove few elements from the "front" and relieve some occupied space, even then we are not able to add anymore elements as the "rear" has already reached the Queue's rear most position.

The solution lies in a type of queue in which the moment "rear" reaches its end; the "first" element will automatically become the queue's new "rear". This type of queue is well known as circular queue possessing a structure like this in which, once the Queue is full the "First" element of the Queue becomes the "Rear" most element, if and only if the "Front" of it has moved forward;

Circular Queue using an array:-

insert(queue,n,front,rear,item)

This procedure inserts an element item into a queue.

1. If front = 1 and rear = n, or if front = rear

+ 1, then:

Write: overflow, and return

2. [find new value of rear]

If front = NULL , then : [queue initially empty.]

Set front = 1 and rear=1. Else if rear = n, then:

Set rear=1.

Else:

Set  rear = rear + 1. [end of structure.]

3. Set queue[rear] = item. [this inserts new

element.]

4.Return .

delete(queue,n,front,rear,item)

This procedure deletes an element from a queue and assigns it to the variable item.

1.   [queue already empty?] If front = NULL , then:

Write: underflow, and return.

2.   Set item = queue[front].

3.   [find new value of front]

If front = rear , then : [queue has only one element to start].

Set front = NULL and rear = NULL. Else if front = n, then:

Set front=1.

Else:

Set  front = front + 1. [end of structure.]

4.   Return .

Posted Date: 7/9/2012 10:06:44 PM | Location : United States







Related Discussions:- Circular queues and implement circular queues using array, Assignment Help, Ask Question on Circular queues and implement circular queues using array, Get Answer, Expert's Help, Circular queues and implement circular queues using array Discussions

Write discussion on Circular queues and implement circular queues using array
Your posts are moderated
Related Questions
Operations on B-Trees Given are various operations which can be performed on B-Trees: Search Create Insert B-Tree does effort to minimize disk access and t

Instructions : You have to design a doubly linked list container. The necessary classes and their declarations are given below The main() function for testing the yo

How do collisions happen during hashing? Usually the key space is much larger than the address space, thus, many keys are mapped to the same address. Assume that two keys K1 an

Q. Illustrate the result of running BFS and DFS on the directed graph given below using vertex 3 as source.  Show the status of the data structure used at each and every stage.

What are the properties of an algorithsm?

Compare zero-address, one-address, two-address, and three-address machines by writing programs to compute: Y = (A – B X C) / (D + E X F) for each of the four machines. The inst

A town contains a total of 5000 houses. Every house owner has to pay tax based on value of the house. Houses over $200 000 pay 2% of their value in tax, houses over $100 000 pay 1.

Describe an algorithm to play the Game of Nim using all of the three tools (pseudocode, flowchart, hierarchy chart)

Draw trace table and determine output from the following flowchart using following data: Number = 45, -2, 20.5

So far, we now have been concerned only with the representation of single stack. What happens while a data representation is required for several stacks? Let us consider an array X