0% found this document useful (0 votes)
7 views

P5

Programming of c language

Uploaded by

luvu9263
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

P5

Programming of c language

Uploaded by

luvu9263
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
#include<conio.h>
void enqueue();
void dequeue();
void display();
typedef struct node*position;
position front=NULL,rear=NULL,newnode,temp,p;
struct node
{
int data;
position next;
};
void main()
{
int choice;
clrscr();
do
{
printf("\n1.Enqueue \n2.Dequeue \n3.Display \n4.Exit\n");
printf("\n Enter Your Choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
exit(0);
}
}
while(choice<5);
}
void enqueue()
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("\n Enter the data to be enqueued :");
scanf("%d",&newnode->data);
newnode->next=NULL;
if(rear==NULL)
front=rear=newnode;
else
{
rear->next=newnode;
rear=newnode;
}
display();
}
void dequeue()
{
if(front==NULL)
printf("\n Empty Queue!!!!!!!Deletion Not Possible ");
else if(front==rear)
{
printf("\n Front element %d is deleted from queue!!!now queue is empty!!!no more
deletion possible!!!\n",front->data);
front=rear=NULL;
}
else
{
temp=front;
front=front->next;
printf("\n Front element %d deleted from queue!!!\n",temp->data);
free(temp);
}
display();
}
void display()
{
p=front;
while(p!=NULL)
{
printf("%d->",p->data);
p=p->next;
}
printf("Null \n");
}

You might also like