際際滷

際際滷Share a Scribd company logo
LINKED LIST IMPLEMENTATION OF LIST
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void insertAtBeginning(int);
void insertAtEnd(int);
void insertBetween(int,int,int);
void display();
void removeBeginning();
void removeEnd();
void removeSpecific(int);
struct Node
{
int data;
struct Node *next;
}*head = NULL;
void main()
{
int choice,value,choice1,loc1,loc2;
clrscr();
while(1){
mainMenu: printf("nn**** MENU **n1. Insertn2. Displayn3. Deleten4.
ExitnEnter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("Enter the value to be insert: ");
scanf("%d",&value);
while(1){
printf("Where you want to insert: n1. At Beginningn2. At Endn3.
BetweennEnter your choice: ");
scanf("%d",&choice1);
switch(choice1)
{
case 1: insertAtBeginning(value);
break;
case 2: insertAtEnd(value);
break;
case 3: printf("Enter the two values where you wanto insert: ");
scanf("%d%d",&loc1,&loc2);
insertBetween(value,loc1,loc2);
break;
default: printf("nWrong Input!! Try again!!!nn");
goto mainMenu;
}
goto subMenuEnd;
}
subMenuEnd:
break;
case 2: display();
break;
case 3: printf("How do you want to Delete: n1. From Beginningn2. From Endn3.
SpesificnEnter your choice: ");
scanf("%d",&choice1);
switch(choice1)
{
case 1: removeBeginning();
break;
case 2: removeEnd(value);
break;
case 3: printf("Enter the value which you wanto delete: ");
scanf("%d",&loc2);
removeSpecific(loc2);
break;
default: printf("nWrong Input!! Try again!!!nn");
goto mainMenu;
}
break;
case 4: exit(0);
default: printf("nWrong input!!! Try again!!nn");
}
}
}
void insertAtBeginning(int value)
{
struct Node *newNode;
newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = value;
if(head == NULL)
{
newNode->next = NULL;
head = newNode;
}
else
{
newNode->next = head;
head = newNode;
}
printf("nOne node inserted!!!n");
}
void insertAtEnd(int value)
{
struct Node *newNode;
newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = value;
newNode->next = NULL;
if(head == NULL)
head = newNode;
else
{
struct Node *temp = head;
while(temp->next != NULL)
temp = temp->next;
temp->next = newNode;
}
printf("nOne node inserted!!!n");
}
void insertBetween(int value, int loc1, int loc2)
{
struct Node *newNode;
newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = value;
if(head == NULL)
{
newNode->next = NULL;
head = newNode;
}
else
{
struct Node *temp = head;
while(temp->data != loc1 && temp->data != loc2)
temp = temp->next;
newNode->next = temp->next;
temp->next = newNode;
}
printf("nOne node inserted!!!n");
}
void removeBeginning()
{
if(head == NULL)
printf("nnList is Empty!!!");
else
{
struct Node *temp = head;
if(head->next == NULL)
{
head = NULL;
free(temp);
}
else
{
head = temp->next;
free(temp);
printf("nOne node deleted!!!nn");
}
}
}
void removeEnd()
{
if(head == NULL)
{
printf("nList is Empty!!!n");
}
else
{
struct Node *temp1 = head,*temp2;
if(head->next == NULL)
head = NULL;
else
{
while(temp1->next != NULL)
{
temp2 = temp1;
temp1 = temp1->next;
}
temp2->next = NULL;
}
free(temp1);
printf("nOne node deleted!!!nn");
}
}
void removeSpecific(int delValue)
{
struct Node *temp1 = head, *temp2;
while(temp1->data != delValue)
{
if(temp1 -> next == NULL){
printf("nGiven node not found in the list!!!");
goto functionEnd;
}
temp2 = temp1;
temp1 = temp1 -> next;
}
temp2 -> next = temp1 -> next;
free(temp1);
printf("nOne node deleted!!!nn");
functionEnd:
}
void display()
{
if(head == NULL)
{
printf("nList is Emptyn");
}
else
{
struct Node *temp = head;
printf("nnList elements are - n");
while(temp->next != NULL)
{
printf("%d --->",temp->data);
temp = temp->next;
}
printf("%d --->NULL",temp->data);
}
}

More Related Content

What's hot (20)

C++ programs
C++ programsC++ programs
C++ programs
Mukund Gandrakota
Avl tree
Avl treeAvl tree
Avl tree
loyola ICAM college of engineering and technology
Recursion concepts by Divya
Recursion concepts by DivyaRecursion concepts by Divya
Recursion concepts by Divya
Divya Kumari
Data structure circular list
Data structure circular listData structure circular list
Data structure circular list
iCreateWorld
Session07 recursion
Session07 recursionSession07 recursion
Session07 recursion
HarithaRanasinghe
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
ritu1806
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
Lakshmi Sarvani Videla
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
pratikbakane
Stack concepts by Divya
Stack concepts by DivyaStack concepts by Divya
Stack concepts by Divya
Divya Kumari
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
pratikbakane
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
pratikbakane
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
pratikbakane
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
pratikbakane
Circular queue
Circular queueCircular queue
Circular queue
ShobhaHiremath8
Program: Inheritance in Class - to find topper out of 10 students
Program: Inheritance in Class - to find topper out of 10 studentsProgram: Inheritance in Class - to find topper out of 10 students
Program: Inheritance in Class - to find topper out of 10 students
Swarup Boro
5 Rmi Print
5  Rmi Print5  Rmi Print
5 Rmi Print
varadasuren
Program(Output)
Program(Output)Program(Output)
Program(Output)
princy75
Basic Programs of C++
Basic Programs of C++Basic Programs of C++
Basic Programs of C++
Bharat Kalia
犖犖迦犖犖橿犖犖犖 犖犖迦犖迦牽犖∇犖ム顕犖о険犖ム権犢
犖犖迦犖犖橿犖犖犖 犖犖迦犖迦牽犖∇犖ム顕犖о険犖ム権犢犖犖迦犖犖橿犖犖犖 犖犖迦犖迦牽犖∇犖ム顕犖о険犖ム権犢
犖犖迦犖犖橿犖犖犖 犖犖迦犖迦牽犖∇犖ム顕犖о険犖ム権犢
犖犢犖橿犖迦献 犖÷顕犢犖ム犖о犢犖
week-20x
week-20xweek-20x
week-20x
KITE www.kitecolleges.com

Similar to Linked list imp of list (20)

Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
Chaitanya Kn
Lab-2.2 717822E504.pdf
Lab-2.2 717822E504.pdfLab-2.2 717822E504.pdf
Lab-2.2 717822E504.pdf
21E135MAHIESHWARJ
137 Lab-2.2.pdf
137 Lab-2.2.pdf137 Lab-2.2.pdf
137 Lab-2.2.pdf
21E135MAHIESHWARJ
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
teyaj1
class 2.pptxdsafe fnbwfl;d,qgyewbjdkqwd;wd
class 2.pptxdsafe fnbwfl;d,qgyewbjdkqwd;wdclass 2.pptxdsafe fnbwfl;d,qgyewbjdkqwd;wd
class 2.pptxdsafe fnbwfl;d,qgyewbjdkqwd;wd
ankitnegics07
class 2.pptxdsdhwdhwdbgkjbdqwnddbqsddbbd
class 2.pptxdsdhwdhwdbgkjbdqwnddbqsddbbdclass 2.pptxdsdhwdhwdbgkjbdqwnddbqsddbbd
class 2.pptxdsdhwdhwdbgkjbdqwnddbqsddbbd
ankitnegics07
take the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdftake the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdf
fastechsrv
week-13x
week-13xweek-13x
week-13x
KITE www.kitecolleges.com
C program
C programC program
C program
Komal Singh
Linked lists
Linked listsLinked lists
Linked lists
GowriKumar Chandramouli
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
harihelectronicspune
Implement of c &amp; its coding programming by sarmad baloch
Implement of c &amp; its coding  programming by sarmad balochImplement of c &amp; its coding  programming by sarmad baloch
Implement of c &amp; its coding programming by sarmad baloch
Sarmad Baloch
Sorting programs
Sorting programsSorting programs
Sorting programs
Varun Garg
C program to insert a node in doubly linked list
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked list
Sourav Gayen
Data structure lab on practical computer science.docx
Data structure lab on practical computer science.docxData structure lab on practical computer science.docx
Data structure lab on practical computer science.docx
nishapatil20005
Data Structure lab on a practical in computer science
Data Structure lab on a practical in computer scienceData Structure lab on a practical in computer science
Data Structure lab on a practical in computer science
nishapatil20005
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfimplement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
FOREVERPRODUCTCHD
#includeiostream struct node { 油油 char value; 油油 struct no.pdf
#includeiostream struct node { 油油 char value; 油油 struct no.pdf#includeiostream struct node { 油油 char value; 油油 struct no.pdf
#includeiostream struct node { 油油 char value; 油油 struct no.pdf
ankitmobileshop235
Dsa ppt which shows the work done during holidays
Dsa ppt which shows the work done during holidaysDsa ppt which shows the work done during holidays
Dsa ppt which shows the work done during holidays
mkrishna70007
week-14x
week-14xweek-14x
week-14x
KITE www.kitecolleges.com
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
teyaj1
class 2.pptxdsafe fnbwfl;d,qgyewbjdkqwd;wd
class 2.pptxdsafe fnbwfl;d,qgyewbjdkqwd;wdclass 2.pptxdsafe fnbwfl;d,qgyewbjdkqwd;wd
class 2.pptxdsafe fnbwfl;d,qgyewbjdkqwd;wd
ankitnegics07
class 2.pptxdsdhwdhwdbgkjbdqwnddbqsddbbd
class 2.pptxdsdhwdhwdbgkjbdqwnddbqsddbbdclass 2.pptxdsdhwdhwdbgkjbdqwnddbqsddbbd
class 2.pptxdsdhwdhwdbgkjbdqwnddbqsddbbd
ankitnegics07
take the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdftake the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdf
fastechsrv
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
harihelectronicspune
Implement of c &amp; its coding programming by sarmad baloch
Implement of c &amp; its coding  programming by sarmad balochImplement of c &amp; its coding  programming by sarmad baloch
Implement of c &amp; its coding programming by sarmad baloch
Sarmad Baloch
Sorting programs
Sorting programsSorting programs
Sorting programs
Varun Garg
C program to insert a node in doubly linked list
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked list
Sourav Gayen
Data structure lab on practical computer science.docx
Data structure lab on practical computer science.docxData structure lab on practical computer science.docx
Data structure lab on practical computer science.docx
nishapatil20005
Data Structure lab on a practical in computer science
Data Structure lab on a practical in computer scienceData Structure lab on a practical in computer science
Data Structure lab on a practical in computer science
nishapatil20005
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfimplement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
FOREVERPRODUCTCHD
#includeiostream struct node { 油油 char value; 油油 struct no.pdf
#includeiostream struct node { 油油 char value; 油油 struct no.pdf#includeiostream struct node { 油油 char value; 油油 struct no.pdf
#includeiostream struct node { 油油 char value; 油油 struct no.pdf
ankitmobileshop235
Dsa ppt which shows the work done during holidays
Dsa ppt which shows the work done during holidaysDsa ppt which shows the work done during holidays
Dsa ppt which shows the work done during holidays
mkrishna70007

Recently uploaded (20)

Virtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-RevolutionVirtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-Revolution
Ashoka Saket
Explainability and Transparency in Artificial Intelligence: Ethical Imperativ...
Explainability and Transparency in Artificial Intelligence: Ethical Imperativ...Explainability and Transparency in Artificial Intelligence: Ethical Imperativ...
Explainability and Transparency in Artificial Intelligence: Ethical Imperativ...
AI Publications
Mastering Secure Login Mechanisms for React Apps.pdf
Mastering Secure Login Mechanisms for React Apps.pdfMastering Secure Login Mechanisms for React Apps.pdf
Mastering Secure Login Mechanisms for React Apps.pdf
Brion Mario
"Introduction to VLSI Design: Concepts and Applications"
"Introduction to VLSI Design: Concepts and Applications""Introduction to VLSI Design: Concepts and Applications"
"Introduction to VLSI Design: Concepts and Applications"
GtxDriver
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
ariomthermal2031
LA11-Case study of motherboard and internal components of motheroard.docx
LA11-Case study of motherboard and internal components of motheroard.docxLA11-Case study of motherboard and internal components of motheroard.docx
LA11-Case study of motherboard and internal components of motheroard.docx
VidyaAshokNemade
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Priyanka Dange
Intro PPT SY_HONORS.pptx- Teaching scheme
Intro PPT SY_HONORS.pptx- Teaching schemeIntro PPT SY_HONORS.pptx- Teaching scheme
Intro PPT SY_HONORS.pptx- Teaching scheme
Priyanka Dange
Airport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANE
Airport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANEAirport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANE
Airport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANE
Priyanka Dange
Supervised Learning Ensemble Techniques Machine Learning
Supervised Learning Ensemble Techniques Machine LearningSupervised Learning Ensemble Techniques Machine Learning
Supervised Learning Ensemble Techniques Machine Learning
ShivarkarSandip
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
NIT SILCHAR
Shallow base metal exploration in northern New Brunswick.pdf
Shallow base metal exploration in northern New Brunswick.pdfShallow base metal exploration in northern New Brunswick.pdf
Shallow base metal exploration in northern New Brunswick.pdf
DUSABEMARIYA
CNC Technology Unit-4 for IV Year 24-25 MECH
CNC Technology Unit-4 for IV Year 24-25 MECHCNC Technology Unit-4 for IV Year 24-25 MECH
CNC Technology Unit-4 for IV Year 24-25 MECH
C Sai Kiran
windrose1.ppt for seminar of civil .pptx
windrose1.ppt for seminar of civil .pptxwindrose1.ppt for seminar of civil .pptx
windrose1.ppt for seminar of civil .pptx
nukeshpandey5678
22PCOAM16_ML_Unit 1 notes & Question Bank with answers.pdf
22PCOAM16_ML_Unit 1 notes & Question Bank with answers.pdf22PCOAM16_ML_Unit 1 notes & Question Bank with answers.pdf
22PCOAM16_ML_Unit 1 notes & Question Bank with answers.pdf
Guru Nanak Technical Institutions
he Wright brothers, Orville and Wilbur, invented and flew the first successfu...
he Wright brothers, Orville and Wilbur, invented and flew the first successfu...he Wright brothers, Orville and Wilbur, invented and flew the first successfu...
he Wright brothers, Orville and Wilbur, invented and flew the first successfu...
HardeepZinta2
Industry 4.0: Transforming Modern Manufacturing and Beyond
Industry 4.0: Transforming Modern Manufacturing and BeyondIndustry 4.0: Transforming Modern Manufacturing and Beyond
Industry 4.0: Transforming Modern Manufacturing and Beyond
GtxDriver
NFPA 70B & 70E Changes and Additions Webinar Presented By Fluke
NFPA 70B & 70E Changes and Additions Webinar Presented By FlukeNFPA 70B & 70E Changes and Additions Webinar Presented By Fluke
NFPA 70B & 70E Changes and Additions Webinar Presented By Fluke
Transcat
Water Industry Process Automation & Control Monthly - April 2025
Water Industry Process Automation & Control Monthly - April 2025Water Industry Process Automation & Control Monthly - April 2025
Water Industry Process Automation & Control Monthly - April 2025
Water Industry Process Automation & Control
UHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptx
UHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptxUHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptx
UHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptx
ariomthermal2031
Virtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-RevolutionVirtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-Revolution
Ashoka Saket
Explainability and Transparency in Artificial Intelligence: Ethical Imperativ...
Explainability and Transparency in Artificial Intelligence: Ethical Imperativ...Explainability and Transparency in Artificial Intelligence: Ethical Imperativ...
Explainability and Transparency in Artificial Intelligence: Ethical Imperativ...
AI Publications
Mastering Secure Login Mechanisms for React Apps.pdf
Mastering Secure Login Mechanisms for React Apps.pdfMastering Secure Login Mechanisms for React Apps.pdf
Mastering Secure Login Mechanisms for React Apps.pdf
Brion Mario
"Introduction to VLSI Design: Concepts and Applications"
"Introduction to VLSI Design: Concepts and Applications""Introduction to VLSI Design: Concepts and Applications"
"Introduction to VLSI Design: Concepts and Applications"
GtxDriver
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
ariomthermal2031
LA11-Case study of motherboard and internal components of motheroard.docx
LA11-Case study of motherboard and internal components of motheroard.docxLA11-Case study of motherboard and internal components of motheroard.docx
LA11-Case study of motherboard and internal components of motheroard.docx
VidyaAshokNemade
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Priyanka Dange
Intro PPT SY_HONORS.pptx- Teaching scheme
Intro PPT SY_HONORS.pptx- Teaching schemeIntro PPT SY_HONORS.pptx- Teaching scheme
Intro PPT SY_HONORS.pptx- Teaching scheme
Priyanka Dange
Airport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANE
Airport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANEAirport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANE
Airport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANE
Priyanka Dange
Supervised Learning Ensemble Techniques Machine Learning
Supervised Learning Ensemble Techniques Machine LearningSupervised Learning Ensemble Techniques Machine Learning
Supervised Learning Ensemble Techniques Machine Learning
ShivarkarSandip
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
NIT SILCHAR
Shallow base metal exploration in northern New Brunswick.pdf
Shallow base metal exploration in northern New Brunswick.pdfShallow base metal exploration in northern New Brunswick.pdf
Shallow base metal exploration in northern New Brunswick.pdf
DUSABEMARIYA
CNC Technology Unit-4 for IV Year 24-25 MECH
CNC Technology Unit-4 for IV Year 24-25 MECHCNC Technology Unit-4 for IV Year 24-25 MECH
CNC Technology Unit-4 for IV Year 24-25 MECH
C Sai Kiran
windrose1.ppt for seminar of civil .pptx
windrose1.ppt for seminar of civil .pptxwindrose1.ppt for seminar of civil .pptx
windrose1.ppt for seminar of civil .pptx
nukeshpandey5678
22PCOAM16_ML_Unit 1 notes & Question Bank with answers.pdf
22PCOAM16_ML_Unit 1 notes & Question Bank with answers.pdf22PCOAM16_ML_Unit 1 notes & Question Bank with answers.pdf
22PCOAM16_ML_Unit 1 notes & Question Bank with answers.pdf
Guru Nanak Technical Institutions
he Wright brothers, Orville and Wilbur, invented and flew the first successfu...
he Wright brothers, Orville and Wilbur, invented and flew the first successfu...he Wright brothers, Orville and Wilbur, invented and flew the first successfu...
he Wright brothers, Orville and Wilbur, invented and flew the first successfu...
HardeepZinta2
Industry 4.0: Transforming Modern Manufacturing and Beyond
Industry 4.0: Transforming Modern Manufacturing and BeyondIndustry 4.0: Transforming Modern Manufacturing and Beyond
Industry 4.0: Transforming Modern Manufacturing and Beyond
GtxDriver
NFPA 70B & 70E Changes and Additions Webinar Presented By Fluke
NFPA 70B & 70E Changes and Additions Webinar Presented By FlukeNFPA 70B & 70E Changes and Additions Webinar Presented By Fluke
NFPA 70B & 70E Changes and Additions Webinar Presented By Fluke
Transcat
UHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptx
UHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptxUHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptx
UHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptx
ariomthermal2031

Linked list imp of list

  • 1. LINKED LIST IMPLEMENTATION OF LIST #include<stdio.h> #include<conio.h> #include<stdlib.h> void insertAtBeginning(int); void insertAtEnd(int); void insertBetween(int,int,int); void display(); void removeBeginning(); void removeEnd(); void removeSpecific(int); struct Node { int data; struct Node *next; }*head = NULL; void main() { int choice,value,choice1,loc1,loc2; clrscr(); while(1){ mainMenu: printf("nn**** MENU **n1. Insertn2. Displayn3. Deleten4. ExitnEnter your choice: "); scanf("%d",&choice); switch(choice) { case 1: printf("Enter the value to be insert: "); scanf("%d",&value); while(1){ printf("Where you want to insert: n1. At Beginningn2. At Endn3. BetweennEnter your choice: "); scanf("%d",&choice1); switch(choice1) { case 1: insertAtBeginning(value); break; case 2: insertAtEnd(value); break; case 3: printf("Enter the two values where you wanto insert: "); scanf("%d%d",&loc1,&loc2); insertBetween(value,loc1,loc2); break;
  • 2. default: printf("nWrong Input!! Try again!!!nn"); goto mainMenu; } goto subMenuEnd; } subMenuEnd: break; case 2: display(); break; case 3: printf("How do you want to Delete: n1. From Beginningn2. From Endn3. SpesificnEnter your choice: "); scanf("%d",&choice1); switch(choice1) { case 1: removeBeginning(); break; case 2: removeEnd(value); break; case 3: printf("Enter the value which you wanto delete: "); scanf("%d",&loc2); removeSpecific(loc2); break; default: printf("nWrong Input!! Try again!!!nn"); goto mainMenu; } break; case 4: exit(0); default: printf("nWrong input!!! Try again!!nn"); } } } void insertAtBeginning(int value) { struct Node *newNode; newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = value; if(head == NULL) { newNode->next = NULL; head = newNode; } else { newNode->next = head; head = newNode;
  • 3. } printf("nOne node inserted!!!n"); } void insertAtEnd(int value) { struct Node *newNode; newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = value; newNode->next = NULL; if(head == NULL) head = newNode; else { struct Node *temp = head; while(temp->next != NULL) temp = temp->next; temp->next = newNode; } printf("nOne node inserted!!!n"); } void insertBetween(int value, int loc1, int loc2) { struct Node *newNode; newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = value; if(head == NULL) { newNode->next = NULL; head = newNode; } else { struct Node *temp = head; while(temp->data != loc1 && temp->data != loc2) temp = temp->next; newNode->next = temp->next; temp->next = newNode; } printf("nOne node inserted!!!n"); } void removeBeginning() { if(head == NULL) printf("nnList is Empty!!!"); else
  • 4. { struct Node *temp = head; if(head->next == NULL) { head = NULL; free(temp); } else { head = temp->next; free(temp); printf("nOne node deleted!!!nn"); } } } void removeEnd() { if(head == NULL) { printf("nList is Empty!!!n"); } else { struct Node *temp1 = head,*temp2; if(head->next == NULL) head = NULL; else { while(temp1->next != NULL) { temp2 = temp1; temp1 = temp1->next; } temp2->next = NULL; } free(temp1); printf("nOne node deleted!!!nn"); } } void removeSpecific(int delValue) { struct Node *temp1 = head, *temp2; while(temp1->data != delValue) { if(temp1 -> next == NULL){ printf("nGiven node not found in the list!!!");
  • 5. goto functionEnd; } temp2 = temp1; temp1 = temp1 -> next; } temp2 -> next = temp1 -> next; free(temp1); printf("nOne node deleted!!!nn"); functionEnd: } void display() { if(head == NULL) { printf("nList is Emptyn"); } else { struct Node *temp = head; printf("nnList elements are - n"); while(temp->next != NULL) { printf("%d --->",temp->data); temp = temp->next; } printf("%d --->NULL",temp->data); } }