Link List Creation, Insertion, Deletion, Searching |

Link List Creation, Insertion, Deletion, Searching

This is the part 1 one of operation #include #include #include //Creation of node str…

,

,

http://www.alychitech.com/2011/11/link-list-creation-insertion-deletion.html

#include#include#include//Creation of nodestruct node{int value;struct node *next;};//inserting new nodesvoid insert(struct node **start,int v){struct node *ptr;ptr=(struct node *)malloc(sizeof(struct node *));ptr->next=NULL;ptr->value=v;if(*start==NULL)printf(“nList is empty. Please create the list first….”);else{ptr->next=*start;*start=ptr;}}//creation of the first node in the listvoid create_list(struct node **start,int v){struct node *ptr;ptr=(struct node *)malloc(sizeof(struct node *));ptr->next=NULL;ptr->value=v;if(*start==NULL)*start=ptr;elseprintf(“nList has been already created…..”);}//delete the whole listvoid del_whole(struct node **start){if(*start!=NULL)*start=NULL;elseprintf(“nUnder flow…..”);}//disply the listvoid display(struct node *start){struct node *ptr;ptr=start;printf(“nStart Pointer is at %un”,start);while(ptr!=NULL){printf(“nAddress %u Value %dtNext %u”,ptr,ptr->value,ptr->next);ptr=ptr->next;}}//find value from the listvoid find(struct node *start,int val){struct node *ptr;int flag=0;ptr=start;while(ptr!=NULL){if(ptr->value==val){flag=1;break;}elseptr=ptr->next;}if(flag==1)printf(“Value is present at position %u”,ptr);elseprintf(“Sorry your value is not present”);}//find minimum number from the link listvoid min(struct node *start){struct node *ptr;int m;ptr=start;m=ptr->value;while(ptr!=NULL){if(ptr->valuevalue;ptr=ptr->next;}printf(“Minimum %u”,m);}void main(){char ch;int v;struct node *start=NULL;clrscr();//run the loop until user wants to to exit by option 7do{//option listprintf(“n1.Create Listn2.Insertn3.Delete Whole listn4.Search valuen5.Displayn6.Find Minimumn7.Exit”);printf(“nEnter your choice:>>”);scanf(“%d”,&ch);switch(ch){case 1:printf(“Enter value:”);scanf(“%d”,&v);create_list(&start,v);break;case 2:printf(“Enter value:”);scanf(“%d”,&v);insert(&start,v);break;case 3:del_whole(&start);break;case 4:printf(“Enter value:”);scanf(“%d”,&v);find(start,v);getch();break;case 5:display(start);getch();break;case 6:min(start);getch();break;default:printf(“Invalid option has been selected…”);}}while(ch!=7);//end of the loop}//end of the prog

?

Add a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!