Array implementation of a circular queue, Data Structure & Algorithms

Assignment Help:

A circular queue can be implemented through arrays or linked lists. Program 6 gives the array implementation of any circular queue.

Program 6: Array implementation of any Circular queue

include "stdio.h"

void add(int);

void deleteelement(void);

int max=10;         /*the maximum limit for queue has been set*/

static int queue[10];

int front=0, rear=-1; /*queue is initially empty*/

void main()

{

int choice,x;

printf ("Enter # for insertion & $ for removal of front the queue and * for exit");

printf("Enter your choice");

 scanf("%d",&choice);

switch (choice)

{

case 1 :

printf ("Enter element for insertion in queue:");

scanf("%d",&x);

add(x);

break;

case 2 :

deleteelement();

break;

}

}

void add(int y)

{

if(rear == max-1)

rear = 0;

else

rear = rear + 1;

if( front == rear && queue[front] != NULL)

printf("Queue Overflow");

else

queue[rear] = y;

}

void deleteelement()

{

int deleted_front = 0;

if (front == NULL)

printf("Error - Queue empty");

else

{

deleted_front = queue[front];

queue[front] = NULL;

if (front == max-1)

front = 0;

else

front = front + 1;

}

}


Related Discussions:- Array implementation of a circular queue

Functions and modelling the data flows, Read the scenario (Pickerings Prope...

Read the scenario (Pickerings Properties). (a) List the functions of the system, as perceived by an external user. (b) List the external entities. Note that because we are mo

General, whats the definition of ADT and data type?

whats the definition of ADT and data type?

Finite automata, find the grammar of regular expression of (a/?)(a/b)?

find the grammar of regular expression of (a/?)(a/b)?

Storing a sparse matrix in memory, Explain an efficient method of storing a...

Explain an efficient method of storing a sparse matrix in memory. Write a module to find the transpose of the sparse matrix stored in this way. A matrix which contains number o

Calculation of time complexity, Example: Assume the following of code: ...

Example: Assume the following of code: x = 4y + 3 z = z + 1 p = 1 As we have been seen, x, y, z and p are all scalar variables & the running time is constant irrespective

Merging 4 sorted files containing 50, Merging 4 sorted files having 50, 10,...

Merging 4 sorted files having 50, 10, 25 and 15 records will take time  O (100)

Array implementation of lists, In the array implementation of the lists, we...

In the array implementation of the lists, we will use the array to hold the entries and a separate counter to keep track of the number of positions are occupied. A structure will b

Booth algorithm, what is boot algorithm and some example

what is boot algorithm and some example

Prims algorithm, Prim's algorithm employs the concept of sets. Rather than ...

Prim's algorithm employs the concept of sets. Rather than processing the graph by sorted order of edges, this algorithm processes the edges within the graph randomly by building up

Difference between prism''s and kruskal''s algorithm, Difference among Pris...

Difference among Prism's and Kruskal's Algorithm In Kruskal's algorithm, the set A is a forest. The safe edge added to A is always a least-weight edge in the paragraph that lin

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