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

Queuelink 1

Uploaded by

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

Queuelink 1

Uploaded by

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

#include <stdio.

h>
#include <conio.h>
#include <malloc.h>
struct node
{
int val;
struct node*next;
};
struct node*front=NULL;
struct node*rear=NULL;
void insert();
void delete();
void display();
void peek();
struct node*new;
void main()
{
int ch;
printf("\nMEIT ADKAR\n");
do{
printf("\n1.Insert\n2.Delete\n3.Display\n4.Peek\n5.End\n");
printf("Enter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:insert();
break;
case 2:delete();
break;
case 3:display();
break;
case 4:peek();
break;
case 5:printf("Terminated\n");
break;
default:printf("Invalid choice\n");
}
}while(ch!=5);
}

void insert()
{
new=(struct node*)malloc(sizeof(struct node));
printf("Enter value: ");
scanf("%d",&(new->val));
new->next=NULL;
if(front==NULL)
{
front=new;
rear=new;
}
else
{
rear->next=new;
rear=new;
}
}

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

void display()
{
if(front==NULL)
{
printf("Queue empty\n");
}
else
{
struct node*temp;
temp=front;
while(temp!=NULL)
{
printf("%d\t",(temp->val));
temp=temp->next;
}
}
}

void peek()
{
if (front==NULL)
{
printf("Queue not available\n");
}
else
{
printf("%d",(front->val));
}
}

/*******OUTPUT*******/
MEIT ADKAR

1.Insert
2.Delete
3.Display
4.Peek
5.End
Enter your choice: 1
Enter value: 45

1.Insert
2.Delete
3.Display
4.Peek
5.End
Enter your choice: 1
Enter value: 8

1.Insert
2.Delete
3.Display
4.Peek
5.End
Enter your choice: 3
8 45

1.Insert
2.Delete
3.Display
4.Peek
5.End
Enter your choice: 2

1.Insert
2.Delete
3.Display
4.Peek
5.End
Enter your choice: 3
45
1.Insert
2.Delete
3.Display
4.Peek
5.End
Enter your choice: 4
The element at the top of Queue is 45

You might also like