Program to implement a Dynamic Queue using Linked List

Program:

#include <stdio.h>
#include <stdlib.h>
struct student
{
    int rollno;
    char name[20];
    float fee;
    struct student *next;
};
struct student *front = NULL;
struct student *rear = NULL;
void enqueue()
{
    struct student *newstudent = (struct student *)malloc(sizeof(struct student));
    if (newstudent == NULL)
        printf("Overflow: Memory Full. You cant insert more items\n");
    else
    {
        printf("\nenter student roll no: ");
        scanf("%d", &newstudent->rollno);
        printf("enter name: ");
        fflush(stdin);
        gets(newstudent->name);
        printf("enter fee : ");
        scanf("%f", &newstudent->fee);
        newstudent->next = NULL;
        if (front == NULL)
        {
            front = rear = newstudent;
        }
        else
        {
            rear->next = newstudent;
            rear = newstudent;
        }
    }
}
void dequeue()
{
    if (front == NULL)
        printf("underflow!!!. Queue is empty. No item to delete");
    else
    {
        struct student *ptr = front;
        printf("Deleted item is :\n");
        printf("Rollno\tname\tfee");
        printf("\n%d\t%s\t%f\n", front->rollno, front->name, front->fee);
        free(ptr);
        front = front->next;
        if (front == NULL)
            rear = NULL;
    }
}
void peek()
{
    if (front == NULL)
        printf("Queue is empty. No item to display");
    else
    {
        printf("Item at the Front is :\n");
        printf("Rollno\tname\tfee");
        printf("\n%d\t%s\t%f\n", front->rollno, front->name, front->fee);
    }
}
void display()
{
    if (front == NULL)
        printf("Queue is empty. No item to display");
    else
    {
        struct student *ptr = front;
        printf("\nInformation of Queue is : \n");
        printf("Rollno\tname\tfee");
        while (ptr != NULL)
        {
            printf("\n%d\t%s\t%f\n", ptr->rollno, ptr->name, ptr->fee);
            ptr = ptr->next;
        }
    }
}
void main()
{
    int ch;
    printf("****************************************\n");
    printf("****************************************\n");
    printf("**       Dynamic / Linked Queue       **\n");
    printf("**         Using Linked Lists         **\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:

****************************************
****************************************
**       Dynamic / Linked Queue       **
**         Using Linked Lists         **
**   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 student roll no: 1
enter name: Sheetal 
enter fee : 1000

Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit

Enter your choice : 1

enter student roll no: 2
enter name: Amit
enter fee : 2000

Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit

Enter your choice : 1

enter student roll no: 3
enter name: Nidhi
enter fee : 3000

Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit

Enter your choice : 4

Information of Queue is :
Rollno  name    fee
1       Sheetal 1000.000000

2       Amit    2000.000000

3       Nidhi   3000.000000

Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit

Enter your choice : 3
Item at the Front is :
Rollno  name    fee
1       Sheetal 1000.000000

Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit

Enter your choice : 2
Deleted item is :
Rollno  name    fee
1       Sheetal 1000.000000

Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit

Enter your choice : 4

Information of Queue is :
Rollno  name    fee
2       Amit    2000.000000

3       Nidhi   3000.000000

Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit

Enter your choice : 2
Deleted item is :
Rollno  name    fee
2       Amit    2000.000000

Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit

Enter your choice : 4

Information of Queue is :
Rollno  name    fee
3       Nidhi   3000.000000

Options Available are
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit

Enter your choice : 2
Deleted item is :
Rollno  name    fee
3       Nidhi   3000.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
error: You can only copy the programs code and output from this website. You are not allowed to copy anything else.