QUEUE
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
typedef struct stk
{
int info;
struct stk *link;
}node;
node *start;
void create()
{
printf("\n'Create' Function Called\n");
start=NULL;
}
void enqueue()
{
node *ptr;
int i;
ptr=(node*)malloc(sizeof(node));
printf("\nEnqueue Value: ");
scanf("%d",&i);
ptr->info=i;
ptr->link=start;
start=ptr;
}
void display() //DISPLAY
{
node *ptr;
printf("\n\n'Display' Function Called");
ptr=start;
if(start==NULL)
{
printf("\n*Queue Empty 'Underflow'*");
}else
{
while(ptr->link!=NULL)
{
printf("\nInfo= %d",ptr->info);
ptr=ptr->link;
}
printf("\nInfo= %d",ptr->info);
}
printf("\n");
getch();
}
void dequeue()
{
int p;
node *ptr,*ptr1;
printf("\n'Dequeue' Function Called");
ptr=start;
if(start==NULL)
{
printf("\n*Queue Empty 'Underflow'*");
}else
{
if(ptr->link==NULL)
{
start=NULL;
}
while(ptr->link!=NULL)
{
ptr1=ptr;
ptr=ptr->link;
}
ptr1->link=NULL;
}
display();
}
void main()
{
clrscr();
create();
enqueue();
enqueue();
enqueue();
enqueue();
display();
dequeue();
dequeue();
dequeue();
dequeue();
printf("\t\t**END**");
getch();
}
***********************************************************************************
Sample Output:
Comments
Post a Comment
Thanks for the comment and don't forget to subscribe.