Queue Using Linked List 8
Queue Using Linked List 8
Queue Using Linked List 8
Name: Implementation of Queue using Linked List - enqueue() and display() Date:
Fil l the missing code in function enqueue(int ele) and display() in the below code.
The function enqueue(int ele) inserts an element into the queue and it gives "Queue is overflow." error if the maximum
capacity of the queue is reached.
QueueListMain1.c
#include <stdlib.h>
#include <stdio.h>
#include "QueueListEnqueueDisplay.c"
int main() {
int op, x;
while(1) {
printf("1.Enqueue 2.Display 3.Exit\n");
scanf("%d",&op);
switch(op) {
case 1:
scanf("%d",&x);
enqueue(x);
break;
case 2:
display();
break;
case 3:
exit(0);
}
Sasi Institute of Technology and Engineering (Autonomous)
}
QueueListEnqueueDisplay.c
struct queue {
int data;
};
void enqueue(int);
if(temp==NULL)
printf("Queue is overflow.\n");
else
temp->data=ele;
if(front==NULL)
front=temp;
rear=temp;
front->next=NULL;
rear->next=NULL;
else
rear->next=temp;
rear=temp;
rear->next=NULL;
printf("Successfully inserted.\n");
void display();
void display()
struct queue*temp;
temp=front;
if(front==NULL)
printf("Queue is empty.\n");
else
while(temp!=NULL)
printf("%d ",temp->data);
temp=temp->next;
printf("\n");
Test Case - 1
User Output
Test Case - 1
1.Enqueue 2.Display 3.Exit 1
Test Case - 2
User Output
1.Enqueue 2.Display 3.Exit 1
Enter your option : 1
Enter element : 2
Successfully inserted. 1
1.Enqueue 2.Display 3.Exit 1
Enter your option : 1
Enter element : 1
Successfully inserted. 1
1.Enqueue 2.Display 3.Exit 1
Enter your option : 1
Enter element : 3
Successfully inserted. 2
1.Enqueue 2.Display 3.Exit 2
Enter your option : 2
Elements in the queue : 2 1 3 1
1.Enqueue 2.Display 3.Exit 1
Enter your option : 1 Sasi Institute of Technology and Engineering (Autonomous)
Enter element : 2
Successfully inserted. 3
1.Enqueue 2.Display 3.Exit 3
Enter your option : 3
Test Case - 3
User Output
1.Enqueue 2.Display 3.Exit 1
Enter your option : 1
Enter element : 1
Successfully inserted. 1
1.Enqueue 2.Display 3.Exit 1
Test Case - 3
Enter your option : 1