Array implementation of a queue, Data Structure & Algorithms

Assignment Help:

Since the stack is list of elements, the queue is also a list of elements. The stack & the queue differ just in the position where the elements may be added or deleted. Similar to other liner data structures, queues can also be implemented by using arrays. Program 1 lists the implementation of a queue by using arrays.

Program: Array implementation of any Queue

include "stdio.h"

define QUEUE_LENGTH 50

struct queue

{     int element[QUEUE_LENGTH];

int front, rear, choice,x,y;

}

struct queue q;

main()

{

int choice,x;

printf ("enter 1 for add and 2 to eliminate element front the queue")

printf("Enter your alternative")

scanf("%d",&choice);

switch (choice)

{

case 1 :

printf ("Enter element to be inserted :");

scanf("%d",&x);

add(&q,x);

break;

case 2 :

delete();

 break;

}

}

add(y)

{

++q.rear;

if (q.rear < QUEUE_LENGTH)

q.element[q.rear] = y;

else

printf("Queue overflow")

}

delete()

{

if q.front > q.rear printf("Queue empty");

else{

x = q.element[q.front];

q.front++;

}

retrun x;

}


Related Discussions:- Array implementation of a queue

Total impedent of the circuit, an electrical student designed a circuit in...

an electrical student designed a circuit in which the impedence in one part of a series circuit is 2+j8 ohms and the impedent is another part of the circuit is 4-j60 ohm mm program

What is a spanning tree of a graph, What is a Spanning tree of a graph? ...

What is a Spanning tree of a graph? A Spanning Tree is any tree having of vertices of graph tree and some edges of graph is known as a spanning tree.

Write an algorithm inputs speed of cars using pseudocode, Write an algorith...

Write an algorithm by using pseudocode which: Inputs top speeds of 5000 cars Outputs fastest speed and the slowest speed Outputs average speed of all the 5000 cars

Illumination of wire frame, Illumination of wire frame The colour or sh...

Illumination of wire frame The colour or shade that a surface appears to the human eye depends primarily on three  factors : Colour and strength of incoming illumination

SORTING ALGORIthm, the deference between insertion,selection and bubble sor...

the deference between insertion,selection and bubble sort

#title.structured programming, what do you understand by structured program...

what do you understand by structured programming?explain with eg. top down and bottem up programming technique

Determine the critical path and the expected completion, The information in...

The information in the table below is available for a large fund-raising project. a. Determine the critical path and the expected completion time of the project. b. Plot the total

Algorithm that inputs the codes for all items in stock, A shop sells books,...

A shop sells books, magazines and maps. Every item is identified by a unique 4 - digit code. All books have a code which starts with 1, all maps have a code starting with 2 and all

Explain the term totalling, Explain the term totalling To add up a ser...

Explain the term totalling To add up a series numbers the subsequent type of statement must be used: Total = total + number  This literally means (new) total = (old) t

Algorithms for push and pop operation, Q. Suggest a method of implementing ...

Q. Suggest a method of implementing two stacks in one array such that as long as space is there in an array, you should be capable to add an element in either stack. Using proposed

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