## Design and Implement a menu driven Program in C for the operations on Singly Linked List of Student Data with the fields

Program Operations are:
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 and Deletion at End of SLL
d. Perform Insertion and Deletion at Front of SLL
e. Demonstrate how this SLL can be used as STACK and QUEUE f. Exit

Linked List is a linear data structure and it is very common data structure which consists of group of nodes in a sequence which is divided in two parts. Each node consists of its own data and the address of the next node and forms a chain. Linked Lists are used to create trees and graphs.

 They are a dynamic in nature which allocates the memory when required.
 Insertion and deletion operations can be easily implemented.
 Stacks and queues can be easily executed.
 Linked List reduces the access time.
 Linked lists are used to implement stacks, queues, graphs, etc.
 Linked lists let you insert elements at the beginning and end of the list.
 In Linked Lists we don’t need to know the size in advance.

ALGORITHM:
Step 1: Start.
Step 2: Read the value of N. (N student’s information)
Step 2: Create a singly linked list. (SLL)
Step 3: Display the status of SLL.
Step 4: Count the number of nodes.
Step 5: Perform insertion at front of list.
Step 6: Perform deletion at the front of the list.
Step 7: Perform insertion at end of the list.
Step 8: Perform deletion at the end of the list.
Step 9: Demonstrate how singly linked list can be used as stack.
Step 10: Demonstrate how singly linked list can be used as queue.
Step 11: Stop

				
#include<stdio.h>
#include<conio.h>
int MAX=4, count;
struct student
{
char usn[10];
char name[30];
char branch[5];
int sem;
char phno[10];
struct student *next; //Self referential pointer.
};
typedef struct student NODE;
{
NODE *p;
count=0;

while(p!=NULL)
{
p=p->next;
count++;
}
return count;
}
{
NODE *newnode;
newnode=(NODE*)malloc(sizeof(NODE)); //Create first NODE
printf("\nEnter USN, Name, Branch, Sem, Ph.No\n");
flushall();
gets(newnode->usn);
flushall();
gets(newnode->name);
flushall();
gets(newnode->branch);
scanf("%d",&(newnode->sem));
flushall();
gets(newnode->phno);
newnode->next=NULL; //Set next to NULL...
}
{
NODE *p;
printf("\nNo student data\n");
else
{
printf("\n----STUDENT DATA----\n");
printf("\nUSN\tNAME\t\tBRANCH\tSEM\tPh.NO.");
while(p!=NULL)
{
printf("\n%s\t%s\t\t%s\t%d\t%s", p->usn, p->name, p->branch, p->sem, p->phno);
p = p->next; //Go to next node...
}
printf("\nThe no. of nodes in list is: %d",countnodes(head));
}

}
{
NODE *newnode;
{
}
else
{
}
}
{
printf("\nList is Full / Overflow!!");
else
}
{
NODE *p, *newnode;
printf("\nList is Full(QUEUE)!!");
else
{
{
}
else
{

while(p->next!=NULL)
{
p=p->next;
}
p->next=newnode;
}
}
}
{
int ch;
do
{
printf("\n1.Insert at Front(First)\t2.Insert at End(Rear/Last)\t3.Exit");
scanf("%d", &ch);
switch(ch)
{
case 3: break;
}
}while(ch!=3);
}
{
NODE *p;
printf("\nList is Empty/Underflow (STACK/QUEUE)");
else
{
free(p);
printf("\nFront(first)node is deleted");
}
}

{
NODE *p, *q;
while(p->next!=NULL)
{
p=p->next; //Go upto -1 NODE which you want to delete
}
q=p->next;
free(q);//Delete last NODE...
p->next=NULL;
printf("\nLast(end) entry is deleted");
}
{
int ch;
do{
printf("\n1.Delete from Front(First)\t2. Delete from End(Rear/Last))\t3.Exit");
scanf("%d",&ch);
switch(ch)
{
break;
break;
case 3: break;
}
}while(ch!=3);
}
{
int ch;
do
{
printf("\nSSL used as Stack...");
printf("\n 1.Insert at Front(PUSH) \t 2.Delete from Front(POP))\t3.Exit");
scanf("%d", &ch);
switch(ch)
{

case 3: break;
}
}while(ch!=3);
}
{
int ch;
do
{
printf("\nSSL used as Queue...");
printf("\n 1.Insert at Rear(INSERT) \t 2.Delete from Front(DELETE))\t3.Exit");
scanf("%d", &ch);
switch(ch)
{
case 3: break;
}
}while(ch!=3);
}
void main()
{
int ch, i, n;
clrscr();
printf("\n*----------Studednt Database-----------*");
do
{
printf("\n 1.Create\t 2.Display\t 3.Insert\t 4.Delete\t 5.Stack\t 6.Queue\t 7.Exit");
scanf("%d", &ch);
switch(ch)
{
case 1: printf("\nHow many student data you want to create: ");
scanf("%d", &n);

for(i=0;i<n;i++)
break;
break;
break;
break;
break;
break;
case 7: exit(); //Exit...
}
}while(ch!=7);
}


OUTPUT:
1. Create 2. Display 3. Insert 4. Delete 5. Stack 6.Queue 7. Exit
How many student data you want to create: 2
Enter USN, Name, Branch, Sem, Ph.No
1kt12cs001 kumar cs 3 9900099000
Enter USN, Name, Branch, Sem, Ph.No
1kt12is002 ravi is 3 9900099111
1. Create 2. Display 3. Insert 4. Delete 5. Stack 6.Queue 7. Exit
----STUDENT DATA----
USN NAME BRANCH SEM Ph.NO.
1kt12is002 ravi is 3 9900099111
1kt12cs001 kumar cs 3 9900099000
The no. of nodes in list is: 2

1. Create 2. Display 3. Insert 4. Delete 5. Stack 6.Queue 7. Exit
1.Insert at Front(First) 2.Insert at End(Rear/Last) 3.Exit

Enter USN, Name, Branch, Sem, Ph.No
1kt12cs003 suresh cs 3 99000992222
----STUDENT DATA----
USN NAME BRANCH SEM Ph.NO.
1kt12cs003 suresh cs 3 99000992222
1kt12is002 ravi is 3 9900099111
1kt12cs001 kumar cs 3 9900099000
The no. of nodes in list is: 3
1.Insert at Front(First) 2.Insert at End(Rear/Last) 3.Exit
Enter USN, Name, Branch, Sem, Ph.No
1kt12is004 naresh is 3 99000993333
----STUDENT DATA----
USN NAME BRANCH SEM Ph.NO.
1kt12cs003 suresh cs 3 99000992222
1kt12is002 ravi is 3 9900099111
1kt12cs001 kumar cs 3 9900099000
1kt12is004 naresh is 3 99000993333
The no. of nodes in list is: 4
1.Insert at Front(First) 2.Insert at End(Rear/Last) 3.Exit
Enter your choice: 3
1. Create 2. Display 3. Insert 4. Delete 5. Stack 6.Queue 7. Exit
1. Delete from Front (First) 2. Delete from End (Rear/Last) 3.Exit
Front (first) node is deleted
----STUDENT DATA----
USN          NAME     BRANCH SEM Ph.NO.
1kt12is002   ravi       is     3 9900099111
1kt12cs001   kumar      cs     3 9900099000
1kt12is004   naresh     is     3 99000993333
The no. of nodes in list is: 3
1. Delete from Front (First) 2. Delete from End (Rear/Last) 3.Exit
Last (end) node is deleted
----STUDENT DATA----
USN NAME BRANCH SEM Ph.NO.
1kt12is002 ravi is 3 9900099111
1kt12cs001 kumar cs 3 9900099000
The no. of nodes in list is: 2
1. Delete from Front (First) 2. Delete from End (Rear/Last) 3.Exit
1. Create 2. Display 3. Insert 4. Delete 5. Stack 6.Queue 7. Exit
Enter your choice: 7