The term “list” refers to a linear collection of data items. One way to store such data is by means at “array” . The array implementation of list hap certain draw backs there are
These are 3 types.
To insert a node in the linked list we need to specify the element to be inserted and the element in the list after which the element has to be inserted.
Deleting Beginning Node:
Head=Head - > Link free(otr);
ptr1=ptr àlink; ptr à link= ptr1 àlink; free(ptr1);
Implementation of singly linked list # include <studio.h> #include <conio.h> #include<stdlib.h> struct Node { int Data; struct Node *link; }; struct Node*Head; void createList() { int else; struct Node*ptr,*cur; Head=NULL; printf(“Enter Data for the Node -1): “); scanf(“%d”,&ele); while(ele!=-1) { cur=(struct Node*)malloc (size of (structNode)); cur Data=ele; cur Link=NULL; if (Head==NULL) Head=cur; else ptr link =cur; ptr=cur; printf(“Enter Data For The Node -1):”); scanf(“%d”,&ele); } } void Insertion() { int ele,x; char ch; struct Node*ptr,*cur; ptr=Head; cur=(structNode *) malloc (size of (structNode)); printf(“Enter Data for the New Node:”); scanf(“%d”,&x); cur Data=x; cur Link=NULL; printf(“Do you want to insert first(y\n:”); fflush(stdin); scanf(“%c”,&ch); if((ch==’y’) || (ch==’n’)) { cur link =Head; Head =cur; } else { printf(“After which element you want to Insert:”); scanf(“%d”,&ele); while(ptr!=NULL) { if(ptr Data ==ele) { cur Link =ptr à Link; ptr Link= cur; break; } else { ptr =ptr Link; } } } } void Deletion () { int ele; char ch; struct Node*ptr,*ptr1; ptr=Head; printf(“Do you want to Delete First (Y/n):”); scanf(“%c”,&ch); if(ch==’y’|| ch==’n’) { Head=Head Link; free(ptr) } else { printf(“ which element you want to delete:”); scanf(“%d”, &ele); while(ptr!=NULL) { if(ptr Link àData==ele) { ptr1=ptr Link; } } } } void Display() { struct node*ptr; ptr=Head; if(ptr==NULL) { printf(“List is Empty \n”); } else { while(ptr!=NULL) { printf(“%5d”,ptr Data); ptr=ptr Link; } } } void main() { int choice; createlist() printf(“1.INSERTION \n”); printf(“2.DELETION \n”); printf(“3.DISPLAY \n”); printf(“4.EXIT \n”); do { printf(“Enter your choice:”); scanf(“%d”,&choice); switch (choice) { { case1: insertion (); break; case2: deletion (); break; case3: Display(); break; case4: exit(0); } } while (choice<=4); getch(); }
You liked the article?
Like : 0
Vote for difficulty
Current difficulty (Avg): Medium
1/15
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.
Stay Updated
Get stories of change makers and innovators from the startup ecosystem in your inbox