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
If a node in a binary tree is not containing left or right child or it is a leaf node then that absence of child node can be represented by the null pointers. The space engaged by

basic calculation for algorith.

since the gregorian calendar was introduced in 1752,a leap year occurs every 4 years.you are to write a pseudo code to find out whether a year is a leap year.your progrm should dis

Q. Describe the basic concept of binary search technique? Is it more efficient than the sequential search?         Ans : The bin ary search technique:- This tec

if two relations R and S are joined, then the non matching tuples of both R and S are ignored in

Question 1 What is a data structure? Discuss briefly on types of data structures Question 2 Explain the insertion and deletion operation of linked list in detail Qu

Question 1 Write a program in 'C' to read N numbers and print them in descending order Question 2 Discuss the properties of ADT Question 3 Write a note on

Readjusting for tree modification calls for rotations in the binary search tree. Single rotations are possible in the left or right direction for moving a node to the root position

Q. Describe what do you understand by the term array? How does an array vary from an ordinary variable? How are the arrays represented in the specific memory?

State about the Bit String Carrier set of the Bit String ADT is the set of all finite sequences of bits, including empty strings of bits, which we denote λ. This set is {λ, 0