0% found this document useful (0 votes)
4 views2 pages

Ds Exp7

Uploaded by

yenoj36493
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)
4 views2 pages

Ds Exp7

Uploaded by

yenoj36493
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<stdlib.h>
typedef struct queue
{
int data;
struct queue*next;
}QUE;
QUE*front=NULL,*rear=NULL;

void insert()
{
QUE*newnode;
newnode = (QUE*)malloc(sizeof(QUE));
printf("\n Enter the element ");
scanf("%d" , &newnode->data);
newnode ->next=NULL;
if(front==NULL)
front = rear = newnode;
else
{
rear -> next = newnode;
rear = newnode;
}
}

void delete()
{
QUE*temp;
if(front == NULL)
printf("\n Queue is empty");
else
{
temp = front;
front = front -> next;
free(temp);
}
}

void display()
{
QUE*temp;
if(front == NULL)
printf("\n Queue is empty");
else
{
temp = front;
printf("\n Element are ");
while(temp != NULL)
{
printf("%d", temp -> data);
temp = temp -> next;
}
}
}

void main()
{
int choice;
while(1)
{
printf("\n 1.Insert");
printf("\n 2.Delete");
printf("\n 3.Display");
printf("\n 4.Exit");
printf("\n Enter the Choice ");
scanf("%d",&choice);
switch(choice)
{
case 1:insert();
break;
case 2:delete();
break;
case 3:display();
break;
case 4:exit(1);
default:printf("\n Invalid choice");
}
}
}

You might also like