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

#input restricted DEQUE, #why all the 4 operations i.e. insertion n del...

#why all the 4 operations i.e. insertion n deletion from rear end and front end is valid in input restricted DEQUE

Binry trees, Build a class ?Node?. It should have a ?value? that it stores ...

Build a class ?Node?. It should have a ?value? that it stores and also links to its parent and children (if they exist). Build getters and setters for it (e.g. parent node, child n

Implementation of stack, Before programming a problem solution those employ...

Before programming a problem solution those employees a stack, we have to decide how to represent a stack by using the data structures which exist in our programming language. Stac

Definitions of graph, A graph G might be defined as a finite set V of verti...

A graph G might be defined as a finite set V of vertices & a set E of edges (pair of connected vertices). The notation utilized is as follows: Graph G = (V, E) Consider the g

Methods, what is folding method?

what is folding method?

Chaining Method as Method of Collision Resolution , Q. The given values are...

Q. The given values are to be stored in a hash table 25, 42, 96, 101, 102, 162, 197 Explain how the values are hashed by using division technique of hashing with a table

Advantage of list over arrays, The advantage of list over Arrays is flexibi...

The advantage of list over Arrays is flexibility. Over flood is not a problem until the computer memory is bushed. When the individual record are quite large, it may be difficult t

Depth first traversal, A depth-first traversal of a tree visits a nodefirst...

A depth-first traversal of a tree visits a nodefirst and then recursively visits the subtrees of that node. Similarly, depth-first traversal of a graph visits a vertex and then rec

Convertion, how we can convert a graph into tree

how we can convert a graph into tree

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