PGM 7
PGM 7
Develop a menu driven Program in C for the following operations on Singly Linked List(SLL) of
Student Data with the fields: USN, Name, Programme, Sem, PhNo.
b. Display the status of SLL and count the number of nodes in it.
e. Exit.
#include <stdio.h>
#include <stdlib.h>
struct Student {
char USN[15];
char Name[30];
char Programme[20];
int Sem;
};
scanf("%s", newNode->USN);
scanf("%s", newNode->Name);
scanf("%s", newNode->Programme);
printf("Enter Semester: ");
scanf("%d", &newNode->Sem);
scanf("%lld", &newNode->PhNo);
newNode->next = NULL;
return newNode;
newNode->next = *head;
*head = newNode;
// Function to display the status of the linked list and count nodes
if (head == NULL) {
printf("List is empty.\n");
return;
int count = 0;
printf("USN: %s, Name: %s, Programme: %s, Sem: %d, Phone: %lld\n",
count++;
if (*head == NULL) {
*head = newNode;
} else {
current = current->next;
current->next = newNode;
if (*head == NULL) {
return;
}
struct Student* temp = *head;
*head = (*head)->next;
free(temp);
if (*head == NULL) {
return;
if ((*head)->next == NULL) {
free(*head);
*head = NULL;
return;
prev = current;
current = current->next;
free(current);
prev->next = NULL;
next = current->next;
free(current);
current = next;
*head = NULL;
int main() {
int choice;
do {
printf("\nMenu:\n");
printf("6. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
insertFront(&head);
break;
case 2:
displayStatus(head);
break;
case 3:
insertEnd(&head);
break;
case 4:
deleteFront(&head);
break;
case 5:
deleteEnd(&head);
break;
case 6:
freeList(&head);
break;
default:
return 0;