Queue Implementation Using Array

Queue is an another Abstract Data Type, where insertion and deletion can be performed from the one end. In Queue Data Structure, the elements are inserted and deleted in the First in First Out fashion.

In Queue, the insertion is done using rear and deletion is performed through front



Applications of Queue

  1. Network Programming
  2. Operating System
  3. Process Scheduling
  4. Waiting Queue
  5. Access the Shared resource (printer)
  6. Multiprograming
Basic Operation of Queue
  • EnQueue Operation (Insert the data)
  • DeQueue Operation (Deletion of data)
EnQueue Operation
DeQueue Operation

Queue Implementation
  1. Array Implementation
  2. Linked List Implementation
Array Implementation of Queue

#include
#include
int max=10;
int a[10];
int front=-1,rear=-1;

void Inqueue()
{
if(rear==max)
printf("Queue is full");
else
{
int n;
if(front=-1)
front=0;
rear=rear+1;
printf("Insert the data\n");
scanf("%d",&n);
a[rear]=n;
printf("Insertion is sucessfull:%d",rear);
}
}

void Dequeue()
{
if(front==-1 || front>rear)
printf("Queue is empty");
else
{
printf("Dequeue elements are:%d\n",a[front]);
front=front+1;
}
}

void display()
{
if(front==-1)
printf("queue is empty");
else
{
int i;
for(i=front;i<=rear;i++)
{
front=front+1;
printf("\nQueue elements are:%d\n",a[i]);
}
}
}


int main()
{
int choice;
while(1)
{
printf("1:Inqueue operation\n");
printf("2:Dequeue Operation\n");
printf("3:Display\n");
printf("4:exit\n");
printf("-------------------------\n");
printf("enter the choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
   Inqueue();
   break;
case 2:
   Dequeue();
   break;
case 3:
   display();
   break;
case 4:
   exit(0);
   break;
default:
   printf("invalid choice");
}
}
}

This code you can get it on below link

https://drive.google.com/open?id=0B2O8tJ9QXc-3a2hmZWlyQjJ1Rms

Comments

Popular posts from this blog

Types of Algorithm and Its Complexity Analysis

First Step of Problem Solving Using Data Structure and Algorithm

Asymptotic Notations