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
a. Create a SLL of N Students Data by using front insertion.
b. Display the status of SLL and count the number of nodes in it
c. Perform Insertion / Deletion at End of SLL
d. Perform Insertion / Deletion at Front of SLL(Demonstration of stack)
e. Exit
#include<stdio.h>
#include<conio.h>
void insertfront();
void deletefront();
void insertend();
void deleteend();
void display();
void stackdemo();
struct node
char usn[25],name[25],programe[25];
int sem;
long int phone;
struct node *next;
};
struct node *start=NULL;
int count=0;
void main()
int ch,n,i;
clrscr();
printf("[Link] SLL of student nodesin front end\n");
printf("[Link]\n");
printf("[Link]\n");
printf("[Link]\n");
printf("[Link]\n");
printf("[Link]\n");
while(1)
printf("enter yourchoice for SLL operation \n");
scanf("%d",&ch);
switch(ch)
case 1:
insertfront();
break;
case 2: display();
break;
case 3: insertend();
break;
case 4: deleteend();
break;
case 5:stackdemo();
break;
case 6: exit(0);
printf("\n Invalid choice");
break;
}
void insertfront()
struct node *temp,*ptr;
temp=(struct node*)malloc(sizeof(struct node));
if(temp==NULL)
printf("out of memory space\n");
exit(0);
printf("enter the usn,Name,programme,sem,phone number of the student:");
scanf("%s %s %s %d %ld",temp->usn,temp->name,temp->programe,&temp->sem,&temp->phone);
temp->next=NULL;
count++;
if(start==NULL)
start=temp;
else
temp->next=start;
start=temp;
void insertend()
struct node *temp,*ptr;
temp=(struct node*)malloc(sizeof(struct node));
if(temp==NULL)
printf("out of memory space\n");
exit(0);
printf("enter the usn,Name,programme,sem,phone number of the student:");
scanf("%s %s %s %d %ld",temp->usn,temp->name,temp->programe,&temp->sem,&temp->phone);
temp->next=NULL;
count++;
if(start==NULL)
start=temp;
else
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=temp;
void deletefront()
struct node *ptr;
if(ptr==NULL)
printf("list is empty\n");
return;
else
ptr=start;
start=start->next;
printf("\nThe student node with usn %s is deleted\n",ptr->usn);
count--;
free(ptr);
void deleteend()
struct node *ptr,*temp;
if(start==NULL)
printf("list is empty\n");
return;
else if(start->next==NULL)
ptr=start;
start=NULL;
printf("\nThe student node with usn %s is deleted",ptr->usn);
free(ptr);
count--;
else
ptr=start;
while(ptr->next!=NULL)
{
temp=ptr;
ptr=ptr->next;
temp->next=NULL;
printf("\nThe student node with usn %s is deleted\n",ptr->usn);
free(ptr);
count--;
void display()
struct node *ptr;
int num=1;
if(start==NULL)
printf("list is empty\n");
return;
else
ptr=start;
printf("the elements in the list are\n");
while(ptr!=NULL)
printf("\nNum:%d | USN:%s | Name:%s | programe:%s | sem:%d | ph:%d|",num,ptr->usn,ptr-
>name,ptr->programe,ptr->sem,ptr->phone);
ptr=ptr->next;
num++;
}
printf("\n No of student nodes is %d\n",count);
void stackdemo()
int ch;
while(1)
printf("\n Stack demo using SLL\n");
printf("\n 1: Push \n 2: Pop \n 3: Display \n 4: Exit \n");
printf("\n Enter your choice");
scanf("%d", &ch);
switch(ch)
case 1: insertfront();
break;
case 2: deletefront();
break;
case 3: display();
break;
default: return;