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

Explain about the containers, Containers Introduction Simple abstr...

Containers Introduction Simple abstract data types are useful for manipulating simple sets of values, such as integers or real numbers however more complex abstract data t

Pseudocodes, how to write a pseudo code using Kramer''s rule

how to write a pseudo code using Kramer''s rule

Surrounding of sub division method, Surrounding of sub division method ...

Surrounding of sub division method A polygon surrounds a viewport if it completely encloses or covers the viewport. This happens if none of its sides cuts any edge of the viewp

Recursive function, The location of a node in a binary search tree is defin...

The location of a node in a binary search tree is defined as a string such as LLRRL, which represents the node that you find by starting at the root, and traversing Left, traverse

Postorder traversal of a binary tree, Postorder traversal of a binary tree ...

Postorder traversal of a binary tree struct NODE { struct NODE *left; int value;     /* can take any data type */ struct NODE *right; }; postorder(struct NODE

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

Sorting, explain quick sort algorithm

explain quick sort algorithm

Procedures, what is far and near procedures in system programming?

what is far and near procedures in system programming?

Declaring a two dimensional array, Declaring a two dimensional array   A...

Declaring a two dimensional array   A two dimensional array is declared same to the way we declare a one-dimensional array except that we state the number of elements in both di

Full binary trees, Full Binary Trees: A binary tree of height h that had 2...

Full Binary Trees: A binary tree of height h that had 2h -1 elements is called a Full Binary Tree. Complete Binary Trees: A binary tree whereby if the height is d, and all of

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