Define queue as an ADT. Write an algorithm for basic operations in circular queue in array implementation.

This answer is restricted. Please login to view the answer of this question.

Login Now

Queue as ADT:

A queue q of type T is a finite sequence of elements with the operations.

  1. MakeEmpty(q): To make q as an empty queue
  2. IsEmpty(q): To check whether the queue q is empty. Return true if queue is empty otherwise return false.
  3. IsFull(q): To check whether the queue q is full. Return true if queue is full otherwise return false.
  4. Enqueue(q, x): To insert an item x at the rear of the queue, if and only if q is not full
  5. Dequeue(q, x): To delete an item x from the front of the queue, if and only if q is not empty
  6. Traverse(q): To read entire queue that is to display the content of queue

Circular Queue is an linear data structure in which the operations are performed based on FIFO principle and last portion is connected back to first position to make a circle.

Algorithm for Basic Operations of Circular Queue:

1. Insert an Element:

Assume that rear and front are initially set to MAXSIZE-1.

1. if(front == (rear + 1) % MAXSIZE)
        print Queue is full and exit;
   else
        rear = (rear + 1) % MAXSIZE;
2. queue[rear] = item;
3. End

2. Deleting an Element:

Assume that rear and front are initially set to MAXSIZE-1.

1. if (rear == front)
      print Queue is empty and exit;
2. front = (front + 1) % MAXSIZE;
3. item = cqueue[front];
4. return item;
5. End
If you found any type of error on the answer then please mention on the comment or report an answer or submit your new answer.
Leave your Answer:

Click here to submit your answer.

Discussion
0 Comments
  Loading . . .