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

Examination, Write an algorithm for binary search. What are its limitations...

Write an algorithm for binary search. What are its limitations? .

Representation of arrays, REPRESENTATION OF ARRAYS This is not uncommon...

REPRESENTATION OF ARRAYS This is not uncommon to determine a large number of programs which procedure the elements of an array in sequence. However, does it mean that the eleme

State algorithm to insert node p at the end of a linked list, Algo rithm t...

Algo rithm to Insert a Node p at the End of a Linked List is explained below Step1:   [check for space] If new1= NULL output "OVERFLOW" And exit Step2:   [Allocate fr

Pseudo code, I need help writing a pseudocode for my assignment can anyone ...

I need help writing a pseudocode for my assignment can anyone help?

Pre-order and post order traversal of a binary tree, The pre-order and post...

The pre-order and post order traversal of a Binary Tree generates the same output. The tree can have maximum One node

Algorithm for determining who won rock paper scissors game, Suppose you are...

Suppose you are given the results of 5 games of rock-paper-scissors. The results are given to you on separate pieces of paper; each piece says either 'A' if the first person won, o

Array vs. ordinary variable, Q. Describe what do you understand by the term...

Q. Describe what do you understand by the term array? How does an array vary from an ordinary variable? How are the arrays represented in the specific memory?

Stack and queue, write a algorithsm in c to perform push and pop operation...

write a algorithsm in c to perform push and pop operations stastic implementation using array ?

Big o notation, This notation gives an upper bound for a function to within...

This notation gives an upper bound for a function to within a constant factor. Given Figure illustrates the plot of f(n) = O(g(n)) depend on big O notation. We write f(n) = O(g(n))

Algorithm for binary search, Q. Write down the algorithm for binary search....

Q. Write down the algorithm for binary search. Which are the conditions under which sequential search of a list is preferred over the binary search?

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