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

Assignment Help:

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 .


Related Discussions:- Circular queues and implement circular queues using array

Find a minimum cost spanning arborescence rooted, Find a minimum cost spann...

Find a minimum cost spanning arborescence rooted at r for the digraph shown below, using the final algorithm shown in class. Please show your work, and also give a final diagram wh

Lists, In the earlier unit, we have discussed about the arrays. Arrays are ...

In the earlier unit, we have discussed about the arrays. Arrays are data structures of fixed size. Insertion & deletion involves reshuffling of array elements. Thus, arraymanipulat

Which sorting methods sorting a list which is almost sorted, Which sorting ...

Which sorting methods would be most suitable for sorting a list which is almost sorted  Bubble Sorting method.

Programs, Develop a program that accepts the car registration( hint: LEA 43...

Develop a program that accepts the car registration( hint: LEA 43242010)

Data Mining and Neural Networks, I am looking for some help with a data min...

I am looking for some help with a data mining class with questions that are about neural networks and decision trees. Can you help? I can send document with questions.

Which sorting algorithm is adaptable to singly linked list, Which sorting a...

Which sorting algorithm is easily adaptable to singly linked lists? Simple Insertion sor t is easily adabtable to singly linked list.

Adjacency matrix, Q. Give the adjacency matrix for the graph drawn below:  ...

Q. Give the adjacency matrix for the graph drawn below:                                                 Ans: Adjacency matrix for the graph given to us

Maximum numbers of nodes a binary tree of depth d, Maximum numbers of nodes...

Maximum numbers of nodes a binary tree of depth d The maximum numbers of nodes a binary tree of depth d can have is 2 d+1 -1.

What is binary search, What is binary search?   Binary search is most ...

What is binary search?   Binary search is most useful when list is sorted. In binary search, element present in middle of the list is determined. If key (the number to search)

Tree traversals, There are three kinds of tree traversals, namely, Postorde...

There are three kinds of tree traversals, namely, Postorder , Preorder and Inorder. Preorder traversal: Each of nodes is visited before its children are visited; first the roo

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd