S3 CS QUEUE USING LS CEK
#include <stdio.h> }} }
#include <stdlib.h> void enQ(int val)
struct node {
{ struct node *newnode = (struct node *)malloc(sizeof(struct
node));
int data;
newnode->data = val;
struct node *next;
newnode->next = NULL;
} *front = NULL, *rear = NULL;
if (front == NULL)
void enQ(int);
front = rear = newnode;
void deQ();
else
void display();
{
void main()
rear->next = newnode;
{
rear = newnode;
int ch, val;
}
printf("Queue using Linked List");
}
for (;;)
void deQ()
{
{
printf("\n1.enQ\t2.deQ\t3.Display\t4.Exit\tChoice: ");
if (front == NULL)
scanf("%d", &ch);
printf("Empty Q");
switch (ch)
else
{
{
case 1:
struct node *temp = front;
printf("Enter value: ");
front = front->next;
scanf("%d", &val);
free(temp);
enQ(val);
}
break;
}
case 2:
void display() {
deQ();
if (front == NULL)
break;
printf("Empty Q");
case 3:
else {
display();
struct node *temp = front;
break;
printf("Queue: ");
case 4:
for (temp; temp->next != NULL; temp = temp->next)
return;
printf("%d--->", temp->data);
default:
printf("%d--->NULL", temp->data);
printf("Invalid Input");
} }