RSS

Insertion/Deletion in a Queue Data Structure

08 Mar

Insertion/Deletion in a Queue Data Structure in C

#include<stdio.h>
#include<conio.h>
#include<process.h>
int queue[5];
long front,rear;
void display();
void main()
{
int choice,info;
clrscr();
//initilisin queue
int tqueue();
while(1)
{
clrscr();
//displaying menu
printf(“MENU \n”);
printf(“1: insert an element in queue\n”);
printf(“2: delete an element from queue\n”);
printf(“3: display the queue\n”);
printf(“exit!\n”);
printf(“your choice:”);
scanf(“%i”,&choice);
switch(choice)
{
case 1: if(rear<4)
{
printf(“enter the no”);
scanf(“%d”,&info);
if(front==-1)
{
front=0;
rear=0;
}
else
rear=rear+1;
queue[rear]=info;
}
else
printf(“queue is full”);
break;
case 2:int info;
if(front!=-1)
{
info=queue[front];
if(front==rear)
{
front=-1;
rear=-1;
}
else
front=front+1;
printf(“no deleted is =%d”,info);
}
else
printf(“queue is empty”);
break;
case 3: display();
break;
case 4: exit(0);
break;
default: printf(“you entered wrong choice!”);
break;
}
}
}
void initqueue()
{
//initilising front & rear to -1
front=rear=-1;
}
/*displays the current position of the queue*/
void display()
{
int i;
//displaying elements in queue
for(i=front;i<=rear;i++)
printf(“%i\n”,queue[i]);
getch();
}

 

Advertisements
 
Leave a comment

Posted by on March 8, 2011 in C/C++

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: