Program:
#include <stdio.h>
#include <stdlib.h>
struct student
{
int rollno;
char name[10];
float fee;
};
int front = -1;
int rear = -1;
struct student qu[5];
void enqueue()
{
if (rear == 4)
printf("Overflow: Queue is Full. You cannot add more items");
else
{
if (front == -1)
front = rear = 0;
else
rear = rear + 1;
printf("\nenter rollno");
scanf("%d", &qu[rear].rollno);
printf("\nenter name");
fflush(stdin);
gets(qu[rear].name);
printf("\nenter fee");
scanf("%f", &qu[rear].fee);
}
}
void dequeue()
{
if (front == -1)
printf("underflow!!!. Queue is empty. No item to delete");
else
{
printf("Deleted item is : %d\t%s\t%f", qu[front].rollno, qu[front].name, qu[front].fee);
if (front == rear)
front = rear = -1;
else
front = front + 1;
}
}
void peek()
{
if (front == -1)
printf("Queue is empty. No item to display");
else
{
printf("Item at the Front is :%d\t%s\t%f", qu[front].rollno, qu[front].name, qu[front].fee);
}
}
void display()
{
if (front == -1)
printf("Queue is empty. No item to display");
else
{
int i;
printf("\nInformation of Queue is : \n");
for (i = front; i <= rear; i++)
printf("\n%d\t%s\t%f", qu[i].rollno, qu[i].name, qu[i].fee);
}
}
void main()
{
int ch;
printf("****************************************\n");
printf("****************************************\n");
printf("** Static Linear Queue **\n");
printf("** Using Array of Structure **\n");
printf("** Program Created By Sheetal Garg **\n");
printf("** Assistant professor **\n");
printf("** 9467863365 **\n");
printf("****************************************\n");
printf("****************************************\n");
while (1)
{
printf("\nOptions Available are\n");
printf("1. Enqueue \n");
printf("2. Dequeue \n");
printf("3. Peek \n");
printf("4. Display \n");
printf("5. Exit \n");
printf("\nEnter your choice : ");
scanf("%d", &ch);
switch (ch)
{
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
peek();
break;
case 4:
display();
break;
case 5:
exit(0);
default:
printf("Wrong choice entered");
}
}
}
Output:
****************************************
****************************************
** Static Linear Queue **
** Using Array of Structure **
** Program Created By Sheetal Garg **
** Assistant professor **
** 9467863365 **
****************************************
****************************************
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 1
enter rollno1
enter nameSheetal
enter fee1000
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 1
enter rollno2
enter nameAmit
enter fee5000
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 1
enter rollno3
enter nameNidhi
enter fee1000
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 1
enter rollno4
enter nameAnsh
enter fee1000
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 1
enter rollno5
enter nameSaksham
enter fee2000
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 1
Overflow: Queue is Full. You cannot add more items
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 4
Information of Queue is :
1 Sheetal 1000.000000
2 Amit 5000.000000
3 Nidhi 1000.000000
4 Ansh 1000.000000
5 Saksham 2000.000000
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 3
Item at the Front is :1 Sheetal 1000.000000
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 2
Deleted item is : 1 Sheetal 1000.000000
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 1
Overflow: Queue is Full. You cannot add more items
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 4
Information of Queue is :
2 Amit 5000.000000
3 Nidhi 1000.000000
4 Ansh 1000.000000
5 Saksham 2000.000000
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 2
Deleted item is : 2 Amit 5000.000000
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 4
Information of Queue is :
3 Nidhi 1000.000000
4 Ansh 1000.000000
5 Saksham 2000.000000
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 2
Deleted item is : 3 Nidhi 1000.000000
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 4
Information of Queue is :
4 Ansh 1000.000000
5 Saksham 2000.000000
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 2
Deleted item is : 4 Ansh 1000.000000
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 4
Information of Queue is :
5 Saksham 2000.000000
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 2
Deleted item is : 5 Saksham 2000.000000
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 4
Queue is empty. No item to display
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 2
underflow!!!. Queue is empty. No item to delete
Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter your choice : 5