#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
typedef struct
qq
{
int data;
struct qq *link;
}qnode;
typedef struct
{
qnode
*front,*rear;
}lqueue;
lqueue
q;
void
main()
{
void
insert(int x);
void
delete(int *x);
void
show();
int
choice,value;
q.front=NULL;
q.rear=NULL;
do
{
clrscr();
printf("\n\n\t\t\tLINKED QUEUE");
printf("\n\t\t\t************");
printf("\nMENU");
printf("\n====");
printf("\n\t 1.INSERT");
printf("\n\t 2.DELETE");
printf("\n\t 3.SHOW");
printf("\n\t 4.EXIT");
printf("\n\nEnter the choice :->");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\n
ENTER THE VALUE :->");
scanf("%d",&value);
insert(value);
getch();
break;
case 2:
delete(&value);
getch();
break;
case 3:
show();
getch();
break;
case 4:
exit(0);
getch();
}
}while(choice!=4);
}
void
insert(int x)
{
qnode *newnode;
newnode=(qnode*)malloc(sizeof(qnode));
newnode->data=x;
newnode->link=NULL;
if(q.rear==NULL)
q.front=q.rear=newnode;
else
{
q.rear->link=newnode;
q.rear=newnode;
}
printf("\n%d IS INSERTED",x);
}
void
delete(int *x)
{
if(q.front==NULL)
printf("\nQUEUE IS EMPTY \n");
else
{
qnode *temp=q.front;
*x=q.front->data;
q.front=q.front->link;
if(q.front==NULL)
q.rear=NULL;
free(temp);
printf("\n
%d IS DELETED",*x);
}
}
void
show()
{
if(q.front==NULL)
printf("\n QUEUE IS
EMPTY");
else
{
qnode *temp=q.front;
while(temp)
{
printf("\n %d is",temp->data);
temp=temp->link;
}
}
}
No comments:
Post a Comment