Exp6 Shivansh
Exp6 Shivansh
Experiment No.6
PROBLEM STATEMENT: Given a set of integer values as data items, write a C program to implement a singly linked list and perform operations of insertion, deletion sorting and display.
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct node
int data;
};


int main()
int option;
do
printf("\n 13.EXIT");
scanf("%d",&option);
switch(option)


case 1: start=create_ll(start);
break;
case 2: start=display(start);
break;
case 3: start=insert_beg(start);
break;
case 4: start=insert_end(start);
break;
case 5: start=insert_before(start);
break;
case 6: start=insert_after(start);
break;
case 7: start=delete_beg(start);
break;
case 8: start=delete_end(start);
break;
case 9: start=delete_node(start);
break;
case 10:start=delete_after(start);
break;
case 11:start=delete_list(start);
break;


case 12:start=sort_list(start);
break;
}while(option!=13);
return 0;
int num;
scanf("%d",&num);
while(num!=-1)
new_node->data=num;
if(start==NULL)
new_node->next=NULL;
start=new_node;
else
ptr=start;EXPERIMENT 6


#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct node
int data;
};
int main()


int option;
do
printf("\n 13.EXIT");
scanf("%d",&option);
switch(option)
case 1: start=create_ll(start);
break;


case 2: start=display(start);
break;
case 3: start=insert_beg(start);
break;
case 4: start=insert_end(start);
break;
case 5: start=insert_before(start);
break;
case 6: start=insert_after(start);
break;
case 7: start=delete_beg(start);
break;
case 8: start=delete_end(start);
break;
case 9: start=delete_node(start);
break;
case 10:start=delete_after(start);
break;
case 11:start=delete_list(start);
break;
case 12:start=sort_list(start);
break;
}while(option!=13);


return 0;
int num;
scanf("%d",&num);
while(num!=-1)
new_node->data=num;
if(start==NULL)
new_node->next=NULL;
start=new_node;
else
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
new_node->next=NULL;


scanf("%d",&num);
return start;
ptr=start;
while(ptr!=NULL)
{ printf("\t %d",ptr->data);
ptr=ptr->next;
return start;
int num;
scanf("%d",&num);
new_node->data=num;
new_node->next=start;


start=new_node;
return start;
int num;
scanf("%d",&num);
new_node->data=num;
new_node->next=NULL;
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
return start;
int num,val;
scanf("%d",&num);
printf("\n Enter the value before which the data has to be inserted :");


scanf("%d",&val);
new_node->data=num;
ptr=start;
while(ptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;
int num,val;
scanf("%d",&num);
printf("\n Enter the value after which the data has to be inserted:");
scanf("%d",&val);
new_node->data=num;
ptr=start;
preptr=ptr;
while(preptr->data!=val)


{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;
int val;
scanf("%d",&val);
ptr=start;
if(ptr->data==val)
start=delete_beg(start);
return start;
else
while(ptr->data!=val)
preptr=ptr;
ptr=ptr->next;


preptr->next=ptr->next;
free(ptr);
return start;
ptr=start;
start=start->next;
free(ptr);
return start;
ptr=start;
while(ptr->next!=NULL)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=NULL;
free(ptr);
return start;


int val;
printf("\n Enter the value after which the node has to be deleted:");
scanf("%d",&val);
ptr=start;
preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;
free(ptr);
return start;
if(start!=NULL)
ptr=start;
while(ptr!=NULL)


start=delete_beg(ptr);
ptr=start;}
return start;
int temp;
ptr1=start;
while(ptr1->next!=NULL)
ptr2=ptr1->next;
while(ptr2!=NULL)
if((ptr1->data)>(ptr2->data))
temp=ptr1->data;
ptr1->data=ptr2->data;
ptr2->data=temp;
ptr2=ptr2->next;
ptr1=ptr1->next;


return start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
new_node->next=NULL;
scanf("%d",&num);
return start;
ptr=start;
while(ptr!=NULL)
{ printf("\t %d",ptr->data);
ptr=ptr->next;
return start;


int num;
scanf("%d",&num);
new_node->data=num;
new_node->next=start;
start=new_node;
return start;
int num;
scanf("%d",&num);
new_node->data=num;
new_node->next=NULL;
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
return start;


int num,val;
scanf("%d",&num);
printf("\n Enter the value before which the data has to be inserted :");
scanf("%d",&val);
new_node->data=num;
ptr=start;
while(ptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;
int num,val;
scanf("%d",&num);


printf("\n Enter the value after which the data has to be inserted:");
scanf("%d",&val);
new_node->data=num;
ptr=start;
preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;
int val;
scanf("%d",&val);
ptr=start;
if(ptr->data==val)
start=delete_beg(start);
return start;


else
while(ptr->data!=val)
preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;
free(ptr);
return start;
ptr=start;
start=start->next;
free(ptr);
return start;
ptr=start;


while(ptr->next!=NULL)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=NULL;
free(ptr);
return start;
int val;
printf("\n Enter the value after which the node has to be deleted:");
scanf("%d",&val);
ptr=start;
preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;
free(ptr);
return start;


if(start!=NULL)
ptr=start;
while(ptr!=NULL)
start=delete_beg(ptr);
ptr=start;}
return start;
int temp;EXPERIMENT 6
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct node


int data;
};
int main()
int option;
do


printf("\n 13.EXIT");
scanf("%d",&option);
switch(option)
case 1: start=create_ll(start);
break;
case 2: start=display(start);
break;
case 3: start=insert_beg(start);
break;
case 4: start=insert_end(start);
break;
case 5: start=insert_before(start);
break;


case 6: start=insert_after(start);
break;
case 7: start=delete_beg(start);
break;
case 8: start=delete_end(start);
break;
case 9: start=delete_node(start);
break;
case 10:start=delete_after(start);
break;
case 11:start=delete_list(start);
break;
case 12:start=sort_list(start);
break;
}while(option!=13);
return 0;
int num;


scanf("%d",&num);
while(num!=-1)
new_node->data=num;
if(start==NULL)
new_node->next=NULL;
start=new_node;
else
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
new_node->next=NULL;
scanf("%d",&num);
return start;


ptr=start;
while(ptr!=NULL)
{ printf("\t %d",ptr->data);
ptr=ptr->next;
return start;
int num;
scanf("%d",&num);
new_node->data=num;
new_node->next=start;
start=new_node;
return start;
int num;


scanf("%d",&num);
new_node->data=num;
new_node->next=NULL;
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
return start;
int num,val;
scanf("%d",&num);
printf("\n Enter the value before which the data has to be inserted :");
scanf("%d",&val);
new_node->data=num;
ptr=start;
while(ptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;


preptr->next=new_node;
new_node->next=ptr;
return start;
int num,val;
scanf("%d",&num);
printf("\n Enter the value after which the data has to be inserted:");
scanf("%d",&val);
new_node->data=num;
ptr=start;
preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;


int val;
scanf("%d",&val);
ptr=start;
if(ptr->data==val)
start=delete_beg(start);
return start;
else
while(ptr->data!=val)
preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;
free(ptr);
return start;


ptr=start;
start=start->next;
free(ptr);
return start;
ptr=start;
while(ptr->next!=NULL)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=NULL;
free(ptr);
return start;
int val;
printf("\n Enter the value after which the node has to be deleted:");
scanf("%d",&val);
ptr=start;


preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
}EXPERIMENT 6
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct node
int data;
};


int main()
int option;
do
printf("\n 13.EXIT");
scanf("%d",&option);


switch(option)
case 1: start=create_ll(start);
break;
case 2: start=display(start);
break;
case 3: start=insert_beg(start);
break;
case 4: start=insert_end(start);
break;
case 5: start=insert_before(start);
break;
case 6: start=insert_after(start);
break;
case 7: start=delete_beg(start);
break;
case 8: start=delete_end(start);
break;
case 9: start=delete_node(start);
break;
case 10:start=delete_after(start);
break;
case 11:start=delete_list(start);


break;
case 12:start=sort_list(start);
break;
}while(option!=13);
return 0;
int num;
scanf("%d",&num);
while(num!=-1)
new_node->data=num;
if(start==NULL)
new_node->next=NULL;
start=new_node;
else


ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
new_node->next=NULL;
scanf("%d",&num);
return start;
ptr=start;
while(ptr!=NULL)
{ printf("\t %d",ptr->data);
ptr=ptr->next;
return start;
int num;


scanf("%d",&num);
new_node->data=num;
new_node->next=start;
start=new_node;
return start;
int num;
scanf("%d",&num);
new_node->data=num;
new_node->next=NULL;
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
return start;


int num,val;
scanf("%d",&num);
printf("\n Enter the value before which the data has to be inserted :");
scanf("%d",&val);
new_node->data=num;
ptr=start;
while(ptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;
int num,val;
scanf("%d",&num);
printf("\n Enter the value after which the data has to be inserted:");
scanf("%d",&val);


new_node->data=num;
ptr=start;
preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;
int val;
scanf("%d",&val);
ptr=start;
if(ptr->data==val)
start=delete_beg(start);
return start;
else


while(ptr->data!=val)
preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;
free(ptr);
return start;
ptr=start;
start=start->next;
free(ptr);
return start;
ptr=start;
while(ptr->next!=NULL)
{ preptr=ptr;


ptr=ptr->next;
preptr->next=NULL;
free(ptr);
return start;
int val;
printf("\n Enter the value after which the node has to be deleted:");EXPERIMENT 6
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct node
int data;
};


int main()
int option;
do


printf("\n 13.EXIT");
scanf("%d",&option);
switch(option)
case 1: start=create_ll(start);
break;
case 2: start=display(start);
break;
case 3: start=insert_beg(start);
break;
case 4: start=insert_end(start);
break;
case 5: start=insert_before(start);
break;
case 6: start=insert_after(start);
break;
case 7: start=delete_beg(start);
break;
case 8: start=delete_end(start);
break;


case 9: start=delete_node(start);
break;
case 10:start=delete_after(start);
break;
case 11:start=delete_list(start);
break;
case 12:start=sort_list(start);
break;
}while(option!=13);
return 0;
int num;
scanf("%d",&num);
while(num!=-1)
new_node->data=num;
if(start==NULL)


new_node->next=NULL;
start=new_node;
else
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
new_node->next=NULL;
scanf("%d",&num);
return start;
ptr=start;
while(ptr!=NULL)
{ printf("\t %d",ptr->data);
ptr=ptr->next;


return start;
int num;
scanf("%d",&num);
new_node->data=num;
new_node->next=start;
start=new_node;
return start;
int num;
scanf("%d",&num);
new_node->data=num;
new_node->next=NULL;
ptr=start;
while(ptr->next!=NULL)


ptr=ptr->next;
ptr->next=new_node;
return start;
int num,val;
scanf("%d",&num);
printf("\n Enter the value before which the data has to be inserted :");
scanf("%d",&val);
new_node->data=num;
ptr=start;
while(ptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;


int num,val;
scanf("%d",&num);
printf("\n Enter the value after which the data has to be inserted:");
scanf("%d",&val);
new_node->data=num;
ptr=start;
preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;
int val;
scanf("%d",&val);
ptr=start;


if(ptr->data==val)
start=delete_beg(start);
return start;
else
while(ptr->data!=val)
preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;
free(ptr);
return start;
ptr=start;
start=start->next;
free(ptr);
return start;


ptr=start;
while(ptr->next!=NULL)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=NULL;
free(ptr);
return start;
int val;
printf("\n Enter the value after which the node has to be deleted:");
scanf("%d",&val);
ptr=start;
preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;


free(ptr);
return start;
if(start!=NULL)
ptr=start;
while(ptr!=NULL)
start=delete_beg(ptr);
ptr=start;}
return start;
}EXPERIMENT 6
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct node


int data;
};
int main()
int option;
do


printf("\n 13.EXIT");
scanf("%d",&option);
switch(option)
case 1: start=create_ll(start);
break;
case 2: start=display(start);
break;
case 3: start=insert_beg(start);
break;
case 4: start=insert_end(start);
break;
case 5: start=insert_before(start);
break;


case 6: start=insert_after(start);
break;
case 7: start=delete_beg(start);
break;
case 8: start=delete_end(start);
break;
case 9: start=delete_node(start);
break;
case 10:start=delete_after(start);
break;
case 11:start=delete_list(start);
break;
case 12:start=sort_list(start);
break;
}while(option!=13);
return 0;
int num;


scanf("%d",&num);
while(num!=-1)
new_node->data=num;
if(start==NULL)
new_node->next=NULL;
start=new_node;
else
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
new_node->next=NULL;
scanf("%d",&num);
return start;


ptr=start;
while(ptr!=NULL)
{ printf("\t %d",ptr->data);
ptr=ptr->next;
return start;
int num;
scanf("%d",&num);
new_node->data=num;
new_node->next=start;
start=new_node;
return start;
int num;


scanf("%d",&num);
new_node->data=num;
new_node->next=NULL;
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
return start;
int num,val;
scanf("%d",&num);
printf("\n Enter the value before which the data has to be inserted :");
scanf("%d",&val);
new_node->data=num;
ptr=start;
while(ptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;


preptr->next=new_node;
new_node->next=ptr;
return start;
int num,val;
scanf("%d",&num);
printf("\n Enter the value after which the data has to be inserted:");
scanf("%d",&val);
new_node->data=num;
ptr=start;
preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;


int val;
scanf("%d",&val);
ptr=start;
if(ptr->data==val)
start=delete_beg(start);
return start;
else
while(ptr->data!=val)
preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;
free(ptr);
return start;


ptr=start;
start=start->next;
free(ptr);
return start;
ptr=start;
while(ptr->next!=NULL)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=NULL;
free(ptr);
return start;
int val;
printf("\n Enter the value after which the node has to be deleted:");
scanf("%d",&val);
ptr=start;


preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;
free(ptr);
return start;
if(start!=NULL)
ptr=start;
while(ptr!=NULL)
start=delete_beg(ptr);
ptr=start;}
return start;


int temp;EXPERIMENT 6
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct node
int data;
};


int main()
int option;
do
printf("\n 13.EXIT");
scanf("%d",&option);
switch(option)
case 1: start=create_ll(start);


break;
case 2: start=display(start);
break;
case 3: start=insert_beg(start);
break;
case 4: start=insert_end(start);
break;
case 5: start=insert_before(start);
break;
case 6: start=insert_after(start);
break;
case 7: start=delete_beg(start);
break;
case 8: start=delete_end(start);
break;
case 9: start=delete_node(start);
break;
case 10:start=delete_after(start);
break;
case 11:start=delete_list(start);
break;
case 12:start=sort_list(start);
break;


}while(option!=13);
return 0;
int num;
scanf("%d",&num);
while(num!=-1)
new_node->data=num;
if(start==NULL)
new_node->next=NULL;
start=new_node;
else
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;


ptr->next=new_node;
new_node->next=NULL;
scanf("%d",&num);
return start;
ptr=start;
while(ptr!=NULL)
{ printf("\t %d",ptr->data);
ptr=ptr->next;
return start;
int num;
scanf("%d",&num);


new_node->data=num;
new_node->next=start;
start=new_node;
return start;
int num;
scanf("%d",&num);
new_node->data=num;
new_node->next=NULL;
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
return start;
int num,val;


scanf("%d",&num);
printf("\n Enter the value before which the data has to be inserted :");
scanf("%d",&val);
new_node->data=num;
ptr=start;
while(ptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;
int num,val;
scanf("%d",&num);
printf("\n Enter the value after which the data has to be inserted:");
scanf("%d",&val);
new_node->data=num;
ptr=start;


preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;
int val;
scanf("%d",&val);
ptr=start;
if(ptr->data==val)
start=delete_beg(start);
return start;
else
while(ptr->data!=val)


preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;
free(ptr);
return start;
ptr=start;
start=start->next;
free(ptr);
return start;
ptr=start;
while(ptr->next!=NULL)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=NULL;


free(ptr);
return start;
int val;
printf("\n Enter the value after which the node has to be deleted:");
scanf("%d",&val);
ptr=start;
preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;EXPERIMENT 6
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct node
int data;


};
int main()
int option;
do


printf("\n 13.EXIT");
scanf("%d",&option);
switch(option)
case 1: start=create_ll(start);
break;
case 2: start=display(start);
break;
case 3: start=insert_beg(start);
break;
case 4: start=insert_end(start);
break;
case 5: start=insert_before(start);
break;
case 6: start=insert_after(start);


break;
case 7: start=delete_beg(start);
break;
case 8: start=delete_end(start);
break;
case 9: start=delete_node(start);
break;
case 10:start=delete_after(start);
break;
case 11:start=delete_list(start);
break;
case 12:start=sort_list(start);
break;
}while(option!=13);
return 0;
int num;
scanf("%d",&num);


while(num!=-1)
new_node->data=num;
if(start==NULL)
new_node->next=NULL;
start=new_node;
else
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
new_node->next=NULL;
scanf("%d",&num);
return start;


ptr=start;
while(ptr!=NULL)
{ printf("\t %d",ptr->data);
ptr=ptr->next;
return start;
int num;
scanf("%d",&num);
new_node->data=num;
new_node->next=start;
start=new_node;
return start;
int num;
scanf("%d",&num);


new_node->data=num;
new_node->next=NULL;
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
return start;
int num,val;
scanf("%d",&num);
printf("\n Enter the value before which the data has to be inserted :");
scanf("%d",&val);
new_node->data=num;
ptr=start;
while(ptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;


new_node->next=ptr;
return start;
int num,val;
scanf("%d",&num);
printf("\n Enter the value after which the data has to be inserted:");
scanf("%d",&val);
new_node->data=num;
ptr=start;
preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;


int val;
scanf("%d",&val);
ptr=start;
if(ptr->data==val)
start=delete_beg(start);
return start;
else
while(ptr->data!=val)
preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;
free(ptr);
return start;


ptr=start;
start=start->next;
free(ptr);
return start;
ptr=start;
while(ptr->next!=NULL)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=NULL;
free(ptr);
return start;
int val;
printf("\n Enter the value after which the node has to be deleted:");
scanf("%d",&val);
ptr=start;
preptr=ptr;


while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;
free(ptr);
return start;EXPERIMENT 6
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct node
int data;
};


int main()
int option;
do
printf("\n 13.EXIT");


scanf("%d",&option);
switch(option)
case 1: start=create_ll(start);
break;
case 2: start=display(start);
break;
case 3: start=insert_beg(start);
break;
case 4: start=insert_end(start);
break;
case 5: start=insert_before(start);
break;
case 6: start=insert_after(start);
break;
case 7: start=delete_beg(start);
break;
case 8: start=delete_end(start);
break;
case 9: start=delete_node(start);
break;
case 10:start=delete_after(start);
break;


case 11:start=delete_list(start);
break;
case 12:start=sort_list(start);
break;
}while(option!=13);
return 0;
int num;
scanf("%d",&num);
while(num!=-1)
new_node->data=num;
if(start==NULL)
new_node->next=NULL;
start=new_node;


else
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
new_node->next=NULL;
scanf("%d",&num);
return start;
ptr=start;
while(ptr!=NULL)
{ printf("\t %d",ptr->data);
ptr=ptr->next;
return start;


int num;
scanf("%d",&num);
new_node->data=num;
new_node->next=start;
start=new_node;
return start;
int num;
scanf("%d",&num);
new_node->data=num;
new_node->next=NULL;
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
return start;


int num,val;
scanf("%d",&num);
printf("\n Enter the value before which the data has to be inserted :");
scanf("%d",&val);
new_node->data=num;
ptr=start;
while(ptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;
int num,val;
scanf("%d",&num);


printf("\n Enter the value after which the data has to be inserted:");
scanf("%d",&val);
new_node->data=num;
ptr=start;
preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;
int val;
scanf("%d",&val);
ptr=start;
if(ptr->data==val)
start=delete_beg(start);
return start;


else
while(ptr->data!=val)
{EXPERIMENT 6
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct node
int data;
};


int main()
int option;
do
printf("\n 13.EXIT");
scanf("%d",&option);


switch(option)
case 1: start=create_ll(start);
break;
case 2: start=display(start);
break;
case 3: start=insert_beg(start);
break;
case 4: start=insert_end(start);
break;
case 5: start=insert_before(start);
break;
case 6: start=insert_after(start);
break;
case 7: start=delete_beg(start);
break;
case 8: start=delete_end(start);
break;
case 9: start=delete_node(start);
break;
case 10:start=delete_after(start);
break;
case 11:start=delete_list(start);


break;
case 12:start=sort_list(start);
break;
}while(option!=13);
return 0;
int num;
scanf("%d",&num);
while(num!=-1)
new_node->data=num;
if(start==NULL)
new_node->next=NULL;
start=new_node;
else


ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
new_node->next=NULL;
scanf("%d",&num);
return start;
ptr=start;
while(ptr!=NULL)
{ printf("\t %d",ptr->data);
ptr=ptr->next;
return start;
int num;


scanf("%d",&num);
new_node->data=num;
new_node->next=start;
start=new_node;
return start;
int num;
scanf("%d",&num);
new_node->data=num;
new_node->next=NULL;
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
return start;


int num,val;
scanf("%d",&num);
printf("\n Enter the value before which the data has to be inserted :");
scanf("%d",&val);
new_node->data=num;
ptr=start;
while(ptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;
int num,val;
scanf("%d",&num);
printf("\n Enter the value after which the data has to be inserted:");
scanf("%d",&val);


new_node->data=num;
ptr=start;
preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;
int val;
scanf("%d",&val);
ptr=start;
if(ptr->data==val)
start=delete_beg(start);
return start;
else


while(ptr->data!=val)
preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;
free(ptr);
return start;
ptr=start;
start=start->next;
free(ptr);
return start;
ptr=start;
while(ptr->next!=NULL)
{ preptr=ptr;


ptr=ptr->next;
preptr->next=NULL;
free(ptr);
return start;
int val;
printf("\n Enter the value after which the node has to be deleted:");
scanf("%d",&val);
ptr=start;
preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;
free(ptr);
return start;


if(start!=NULL)
ptr=start;
while(ptr!=NULL)
start=delete_beg(ptr);
ptr=start;}
return start;
int temp;
ptr1=start;
while(ptr1->next!=NULL)
ptr2=ptr1->next;
while(ptr2!=NULL)
if((ptr1->data)>(ptr2->data))
temp=ptr1->data;
ptr1->data=ptr2->data;


ptr2->data=temp;
ptr2=ptr2->next;
ptr1=ptr1->next;
return start;
preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;
free(ptr);
return start;
ptr=start;
start=start->next;
free(ptr);
return start;


ptr=start;
while(ptr->next!=NULL)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=NULL;
free(ptr);
return start;
int val;
printf("\n Enter the value after which the node has to be deleted:");
scanf("%d",&val);
ptr=start;
preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;
free(ptr);


return start;
if(start!=NULL)
ptr=start;
while(ptr!=NULL)
start=delete_beg(ptr);
ptr=start;}
return start;
int temp;
ptr1=start;
while(ptr1->next!=NULL)
ptr2=ptr1->next;
while(ptr2!=NULL)


if((ptr1->data)>(ptr2->data))
temp=ptr1->data;
ptr1->data=ptr2->data;
ptr2->data=temp;
ptr2=ptr2->next;
ptr1=ptr1->next;
return start;
if(start!=NULL)
ptr=start;
while(ptr!=NULL)
start=delete_beg(ptr);
ptr=start;}


return start;
int temp;
ptr1=start;
while(ptr1->next!=NULL)
ptr2=ptr1->next;
while(ptr2!=NULL)
if((ptr1->data)>(ptr2->data))
temp=ptr1->data;
ptr1->data=ptr2->data;
ptr2->data=temp;
ptr2=ptr2->next;
ptr1=ptr1->next;
return start;


free(ptr);
return start;
if(start!=NULL)
ptr=start;
while(ptr!=NULL)
start=delete_beg(ptr);
ptr=start;}
return start;
int temp;
ptr1=start;
while(ptr1->next!=NULL)
ptr2=ptr1->next;


while(ptr2!=NULL)
if((ptr1->data)>(ptr2->data))
temp=ptr1->data;
ptr1->data=ptr2->data;
ptr2->data=temp;
ptr2=ptr2->next;
ptr1=ptr1->next;
return start;
ptr1=start;
while(ptr1->next!=NULL)
ptr2=ptr1->next;
while(ptr2!=NULL)
if((ptr1->data)>(ptr2->data))
temp=ptr1->data;
ptr1->data=ptr2->data;
ptr2->data=temp;


ptr2=ptr2->next;
ptr1=ptr1->next;
return start;
int temp;
ptr1=start;
while(ptr1->next!=NULL)
ptr2=ptr1->next;
while(ptr2!=NULL)
if((ptr1->data)>(ptr2->data))
temp=ptr1->data;
ptr1->data=ptr2->data;
ptr2->data=temp;
ptr2=ptr2->next;


ptr1=ptr1->next;
return start;
scanf("%d",&val);
ptr=start;
preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;
free(ptr);
return start;
if(start!=NULL)
ptr=start;
while(ptr!=NULL)
start=delete_beg(ptr);


ptr=start;}
return start;
int temp;
ptr1=start;
while(ptr1->next!=NULL)
ptr2=ptr1->next;
while(ptr2!=NULL)
if((ptr1->data)>(ptr2->data))
temp=ptr1->data;
ptr1->data=ptr2->data;
ptr2->data=temp;
ptr2=ptr2->next;
ptr1=ptr1->next;
return start;


preptr->next=ptr->next;
free(ptr);
return start;
if(start!=NULL)
ptr=start;
while(ptr!=NULL)
start=delete_beg(ptr);
ptr=start;}
return start;
int temp;
ptr1=start;
while(ptr1->next!=NULL)


ptr2=ptr1->next;
while(ptr2!=NULL)
if((ptr1->data)>(ptr2->data))
temp=ptr1->data;
ptr1->data=ptr2->data;
ptr2->data=temp;
ptr2=ptr2->next;
ptr1=ptr1->next;
return start;
ptr1=start;
while(ptr1->next!=NULL)
ptr2=ptr1->next;
while(ptr2!=NULL)
if((ptr1->data)>(ptr2->data))
temp=ptr1->data;


ptr1->data=ptr2->data;
ptr2->data=temp;
ptr2=ptr2->next;
ptr1=ptr1->next;
return start;
EXPERIMENT 6
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct node
int data;
};


int main()
int option;
do


printf("\n 13.EXIT");
scanf("%d",&option);
switch(option)
case 1: start=create_ll(start);
break;
case 2: start=display(start);
break;
case 3: start=insert_beg(start);
break;
case 4: start=insert_end(start);
break;
case 5: start=insert_before(start);
break;
case 6: start=insert_after(start);
break;
case 7: start=delete_beg(start);


break;
case 8: start=delete_end(start);
break;
case 9: start=delete_node(start);
break;
case 10:start=delete_after(start);
break;
case 11:start=delete_list(start);
break;
case 12:start=sort_list(start);
break;
}while(option!=13);
return 0;
int num;
scanf("%d",&num);
while(num!=-1)


new_node->data=num;
if(start==NULL)
new_node->next=NULL;
start=new_node;
else
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
new_node->next=NULL;
scanf("%d",&num);
return start;
ptr=start;
while(ptr!=NULL)


{ printf("\t %d",ptr->data);
ptr=ptr->next;
return start;
int num;
scanf("%d",&num);
new_node->data=num;
new_node->next=start;
start=new_node;
return start;
int num;
scanf("%d",&num);
new_node->data=num;


new_node->next=NULL;
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
return start;
int num,val;
scanf("%d",&num);
printf("\n Enter the value before which the data has to be inserted :");
scanf("%d",&val);
new_node->data=num;
ptr=start;
while(ptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;


int num,val;
scanf("%d",&num);
printf("\n Enter the value after which the data has to be inserted:");
scanf("%d",&val);
new_node->data=num;
ptr=start;
preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=new_node;
new_node->next=ptr;
return start;
int val;


scanf("%d",&val);
ptr=start;
if(ptr->data==val)
start=delete_beg(start);
return start;
else
while(ptr->data!=val)
preptr=ptr;
ptr=ptr->next;
preptr->next=ptr->next;
free(ptr);
return start;
ptr=start;
start=start->next;


free(ptr);
return start;
ptr=start;
while(ptr->next!=NULL)
{ preptr=ptr;
ptr=ptr->next;
preptr->next=NULL;
free(ptr);
return start;
int val;
printf("\n Enter the value after which the node has to be deleted:");
scanf("%d",&val);
ptr=start;
preptr=ptr;
while(preptr->data!=val)
{ preptr=ptr;


ptr=ptr->next;
preptr->next=ptr->next;
free(ptr);
return start;
if(start!=NULL)
ptr=start;
while(ptr!=NULL)
start=delete_beg(ptr);
ptr=start;}
return start;
int temp;
ptr1=start;


while(ptr1->next!=NULL)
ptr2=ptr1->next;
while(ptr2!=NULL)
if((ptr1->data)>(ptr2->data))
temp=ptr1->data;
ptr1->data=ptr2->data;
ptr2->data=temp;
ptr2=ptr2->next;
ptr1=ptr1->next;
return start;
OUTPUT:






CONCLUSION: Hence, we have implemented a C program to implement a singly linked list and perform operations of insertion,