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

All pairs shortest paths algorithm, In the last section, we discussed regar...

In the last section, we discussed regarding shortest path algorithm that starts with a single source and determines shortest path to all vertices in the graph. In this section, we

High-level and bubble algorithm , 1. Give both a high-level algorithm and a...

1. Give both a high-level algorithm and an implementation (\bubble diagram") of a Turing machine for the language in Exercise 3.8 (b) on page 160. Use the ' notation to show the co

Write an algorithm to input number of passengers travelling, There are ten ...

There are ten stations on a railway line: Train travels in both directions (i.e. from 1 to 10 and then from 10 to 1).  Fare between each station is $2. A passenger input

Program to implementing stack using linked lists, include include i...

include include include /* Definition of structure node */ typedef struct node { int data; struct node *next; } ; /* Definition of push function */

Red-black trees, A Red-Black Tree (RBT) is a type of Binary Search tree wit...

A Red-Black Tree (RBT) is a type of Binary Search tree with one extra bit of storage per node, i.e. its color that can either be red or black. Now the nodes can have any of the col

Define different types of sparse matrix, Q1. Define a sparse matrix. Explai...

Q1. Define a sparse matrix. Explain different types of sparse matrices? Evaluate the method to calculate address of any element a jk of a matrix stored in memory. Q2. A linear

What are circular queues, What are circular queues?  Circular queue: St...

What are circular queues?  Circular queue: Static queues have a very large drawback that once the queue is FULL, even though we erase few elements from the "front" and relieve

Breadth first search, While BFS is applied, the vertices of the graph are d...

While BFS is applied, the vertices of the graph are divided into two categories. The vertices, that are visited as part of the search & those vertices that are not visited as part

Polynomials, Polynomials like  5x 4    +  2x 3    +  7x 2     +  10x  -  8...

Polynomials like  5x 4    +  2x 3    +  7x 2     +  10x  -  8  can  be  represented by using arrays. Arithmetic operations such as addition & multiplication of polynomials are com

LINKED LIST, HOW LINKED LIST HEADER WORKS? HOW TO INSERT AND DELETE ELEMENT...

HOW LINKED LIST HEADER WORKS? HOW TO INSERT AND DELETE ELEMENTS IN LINKED LIST?

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