Queue using Dynamic LinkList:-The Below code can shown you how to implement Queue using dynamic linklist in data structure using C. We can insert the node dynamically and the Linklist works on principal First-In-First-Out(FIFO). The Element can show you the order in which you have inserted and deletion of element can be according to the order in which you have entered means the first inserted element will be deleted first.
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
#include<process.h>
struct node
{
int info;
struct node *next;
};
typedef struct node NODE;
NODE *node=NULL,*start=NULL,*end=NULL;
void insert();
void del();
void disp();
void main()
{
int ch;
clrscr();
while(1)
{
printf("\n1:Insert");
printf("\n2:Delete");
printf("\n3:Display");
printf("\n4:Exit");
printf("\n\tEnter Your Choice:-");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
break;
case 2:
del();
break;
case 3:
disp();
break;
case 4:
exit(1);
default:
printf("\n\tOption Not Available");
break;
}
}
getch();
}
void insert()
{
node=(NODE *)malloc(sizeof(NODE));
printf("\n\tEnter the Element:-");
scanf("%d",&node->info);
node->next=NULL;
if(start==NULL)
{
start=node;
end=node;
}
else
{
end->next=node;
end=node;
}
}
void del()
{
if(start==NULL)
{
printf("\n\tUnderflow Condition No Element To Delete");
}
else
{
printf("\n\t%d is Delete ",start->info);
start=start->next;
}
}
void disp()
{
NODE *temp;
temp=start;
while(temp!=NULL)
{
printf("%d\n",temp->info);
temp=temp->next;
}
}
0 Comment(s)