0% found this document useful (0 votes)
27 views

SLL Program

This C program implements a singly linked list to store student details like USN, name, branch, semester and phone number. It defines a node structure with these details and pointer to next node. Functions are defined to get new node, insert at beginning or end, delete from beginning or end and display the list. The main function takes user input to perform these operations and displays the list.

Uploaded by

Ashish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

SLL Program

This C program implements a singly linked list to store student details like USN, name, branch, semester and phone number. It defines a node structure with these details and pointer to next node. Functions are defined to get new node, insert at beginning or end, delete from beginning or end and display the list. The main function takes user input to perform these operations and displays the list.

Uploaded by

Ashish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

#include<stdio.

h>

#include<stdlib.h>

struct SLL

int sem;

char usn[10],name[20],branch[20],phone[10];

struct SLL *next;

};

typedef struct SLL node;

node *start=NULL;

node* getNode()

node *newnode;

newnode=(node*)malloc(sizeof(node*));

printf("enter the student details usn name branch sem phno\n");

scanf("%s",newnode->usn);

scanf("%s",newnode->name);

scanf("%s",newnode->branch);

fflush(stdin);

scanf("%d",&newnode->sem);

scanf("%s",newnode->phone);

newnode->next=NULL;

return newnode;

void insertbegin()

node *newnode;

newnode=getNode();

if(start==NULL)

start=newnode;
return;

newnode->next=start;

start=newnode;

void insertend()

node *newnode,*temp;

newnode=getNode();

if(start==NULL)

start=newnode;

return;

temp=start;

while(temp->next!=NULL)

temp=temp->next;

temp->next=newnode;

void deletebegin()

node* temp=start;

if(start==NULL)

printf("list is empty\n");

return;

printf("deleted node is %s\n",temp->usn);

start=temp->next;

free(temp);

}
void display()

node* temp=start;

if(start==NULL)

printf("list is empty\n");

return;

printf("list elements are\n");

while(temp!=NULL)

printf("%s\t",temp->usn);

temp=temp->next;

printf("\n");

void deleteend()

node *temp=start,*prev;

if(start==NULL)

printf("list is empty\n");

return;

if(start->next==NULL)

printf("deleted node is %s\n",temp->usn);

start=NULL;

free(temp);

else
{

while(temp->next!=NULL)

prev=temp;

temp=temp->next;

prev->next=NULL;

printf("deleted node is %s\n",temp->usn);

free(temp);

int main()

int choice,n,i;

while(1)

printf("enter your choice 1 for insert begin 2 for insert end 3 for delete begin ");

printf("4 for delete end and 5 for display and 6 for exit\n");

scanf("%d",&choice);

switch(choice)

case 1:printf("enter the no of students\n");

scanf("%d",&n);

for(i=0;i<n;i++)

insertbegin();

break;

case 2:insertend();
break;

case 3:deletebegin();

break;

case 4:deleteend();

break;

case 5:display();

break;

case 6:exit(0);

break;

default:printf("invalid chioce\n");

You might also like