SlideShare a Scribd company logo
1 of 5
Download to read offline
How to build a Linked List that can insert any type of data. For example: SLinkedList abc1;
SLinkedList abc2; SLinkedlist abc3; Please answer in C plus plus, you don't need to develop all
function, just insert data is enough.
Thank you.
Solution
#include
#include
#define LEFT 2
#define RIGHT 3
typedef struct linked_list
{
double data;
struct linked_list *next;
}node;//node declaration for single linked list
/*function prototype declaration*/
void insertion(node **,double);
void erase(node **,node **);
//void left_or_right(node **,node **,int);
node *makenode(double);
void show(node **,node **);
/*main*/
int main()
{
system("clear");
char choice;
double item;
node *start=NULL,*prev=NULL;
do
{
printf(" =========================== tMENU
=========================== t1.Insert t2.Exit Enter your choice :: ");
scanf(" %c",&choice);
switch(choice)
{
case '1':
printf(" Enter item :: ");
scanf("%lf",&item);
insertion(&start,item);//insert function calling
show(&start,&prev);
break;
case '2':
erase(&prev,&start);
printf(" You are exited from the whole program.  ");
exit(1);
default:
printf(" tWrong Choice ");
}
}
while(choice!='2');
return 0;
}
void show(node **start,node **prev)/*this function displays the whole linked list*/
{
if((*start)!=NULL)
{
printf("  X <- ");
node *temp=NULL,*p=*prev,*q=NULL;
while(p!=NULL)
{
if(temp==NULL)
{
temp=makenode(p->data);
}
else
{
q=makenode(p->data);
q->next=temp;
temp=q;
}
p=p->next;
}
while(temp!=NULL)
{
printf("%.0lf <- ",temp->data);
q=temp;
temp=temp->next;
free(q);
q=NULL;
}
printf("b| ");
p=*start;
while(p!=NULL)
{
if(p==*start)
{
printf("%.0lf |-> ",p->data);
}
else
{
printf("%.0lf -> ",p->data);
}
p=p->next;
}
printf(" X   ");
}
else
{
printf("  tEmpty Linked List  ");
}
}
void insertion(node **start,double item)//this function inserts a new node in the linked list
{
node *temp=makenode(item),*p=NULL;
if(*start==NULL)
{
*start=temp;
}
else
{
p=*start;
while(p->next!=NULL)
{
p=p->next;
}
p->next=temp;
}
}
node *makenode(double item)
{
node *temp=NULL;
temp=(node *)malloc(sizeof(node));
if(temp==NULL)
{
printf(" Dynamic memory allocation failed. ");
exit(0);
}
temp->data=item;
temp->next=NULL;
}
void erase(node **prev,node **start)//this function deletes all nodes of the linked list when the
program terminates
{
node *p=NULL;
while(*start!=NULL)
{
p=*start;
*start=(*start)->next;
free(p);
p=NULL;
}
while(*prev!=NULL)
{
p=*prev;
*prev=(*prev)->next;
free(p);
p=NULL;
}
}

More Related Content

Similar to How to build a Linked List that can insert any type of data. For exa.pdf

THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdffathimahardwareelect
 
Using the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfUsing the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfconnellalykshamesb60
 
There are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxThere are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxclarkjanyce
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfformicreation
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Balwant Gorad
 
Use C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdfUse C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdfshalins6
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfrohit219406
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdfadityastores21
 
pleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfpleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfwasemanivytreenrco51
 
What is Linked List in C.docx
What is Linked List in C.docxWhat is Linked List in C.docx
What is Linked List in C.docxnona800027
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
 
Write the definition of the linkedListKeepLast function- (Please write.docx
Write the definition of the linkedListKeepLast function- (Please write.docxWrite the definition of the linkedListKeepLast function- (Please write.docx
Write the definition of the linkedListKeepLast function- (Please write.docxdelicecogupdyke
 
C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdfdeepua8
 
Array linked list.ppt
Array  linked list.pptArray  linked list.ppt
Array linked list.pptWaf1231
 
I need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdfI need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdfeyeonsecuritysystems
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfJUSTSTYLISH3B2MOHALI
 
C++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxC++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxMatthPYNashd
 

Similar to How to build a Linked List that can insert any type of data. For exa.pdf (20)

THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
 
Using the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfUsing the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdf
 
There are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxThere are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docx
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
 
Use C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdfUse C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdf
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdf
 
pleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfpleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdf
 
What is Linked List in C.docx
What is Linked List in C.docxWhat is Linked List in C.docx
What is Linked List in C.docx
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
Write the definition of the linkedListKeepLast function- (Please write.docx
Write the definition of the linkedListKeepLast function- (Please write.docxWrite the definition of the linkedListKeepLast function- (Please write.docx
Write the definition of the linkedListKeepLast function- (Please write.docx
 
C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdf
 
Array linked list.ppt
Array  linked list.pptArray  linked list.ppt
Array linked list.ppt
 
I need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdfI need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdf
 
Adt of lists
Adt of listsAdt of lists
Adt of lists
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
 
C++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxC++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docx
 
Linked list
Linked list Linked list
Linked list
 

More from arpittradersjdr

When light strikes chlorophyll of photosystem II, a molecule loses el.pdf
When light strikes chlorophyll of photosystem II, a molecule loses el.pdfWhen light strikes chlorophyll of photosystem II, a molecule loses el.pdf
When light strikes chlorophyll of photosystem II, a molecule loses el.pdfarpittradersjdr
 
You have persuaded XelPharms CIO that wireless networking would be.pdf
You have persuaded XelPharms CIO that wireless networking would be.pdfYou have persuaded XelPharms CIO that wireless networking would be.pdf
You have persuaded XelPharms CIO that wireless networking would be.pdfarpittradersjdr
 
Where do vesicles come fromA. Plasma membranceB. Nuclear membra.pdf
Where do vesicles come fromA. Plasma membranceB. Nuclear membra.pdfWhere do vesicles come fromA. Plasma membranceB. Nuclear membra.pdf
Where do vesicles come fromA. Plasma membranceB. Nuclear membra.pdfarpittradersjdr
 
Which of the following are statements 1. She is a mathematics maj.pdf
Which of the following are statements 1. She is a mathematics maj.pdfWhich of the following are statements 1. She is a mathematics maj.pdf
Which of the following are statements 1. She is a mathematics maj.pdfarpittradersjdr
 
What problem was IETF DiffServ supposed to solve How did IETF DiffS.pdf
What problem was IETF DiffServ supposed to solve  How did IETF DiffS.pdfWhat problem was IETF DiffServ supposed to solve  How did IETF DiffS.pdf
What problem was IETF DiffServ supposed to solve How did IETF DiffS.pdfarpittradersjdr
 
what causes hydrogen bonds to form between polar moleculesSolut.pdf
what causes hydrogen bonds to form between polar moleculesSolut.pdfwhat causes hydrogen bonds to form between polar moleculesSolut.pdf
what causes hydrogen bonds to form between polar moleculesSolut.pdfarpittradersjdr
 
What are the four main factors involved in the movement of ions acro.pdf
What are the four main factors involved in the movement of ions acro.pdfWhat are the four main factors involved in the movement of ions acro.pdf
What are the four main factors involved in the movement of ions acro.pdfarpittradersjdr
 
Transitional epithelium L x) strained columnar epimeeliamL X) Sol.pdf
Transitional epithelium L x) strained columnar epimeeliamL X) Sol.pdfTransitional epithelium L x) strained columnar epimeeliamL X) Sol.pdf
Transitional epithelium L x) strained columnar epimeeliamL X) Sol.pdfarpittradersjdr
 
The alpha-helix shown below is part of a water-soluble, globular prot.pdf
The alpha-helix shown below is part of a water-soluble, globular prot.pdfThe alpha-helix shown below is part of a water-soluble, globular prot.pdf
The alpha-helix shown below is part of a water-soluble, globular prot.pdfarpittradersjdr
 
Simple squamous epithelium is structured to best provideA. Diffus.pdf
Simple squamous epithelium is structured to best provideA. Diffus.pdfSimple squamous epithelium is structured to best provideA. Diffus.pdf
Simple squamous epithelium is structured to best provideA. Diffus.pdfarpittradersjdr
 
A tower leans at an angle of about 84.7°. The figure shows that 150 .pdf
A tower leans at an angle of about 84.7°. The figure shows that 150 .pdfA tower leans at an angle of about 84.7°. The figure shows that 150 .pdf
A tower leans at an angle of about 84.7°. The figure shows that 150 .pdfarpittradersjdr
 
A sample of 200 people were asked to identify their major source of .pdf
A sample of 200 people were asked to identify their major source of .pdfA sample of 200 people were asked to identify their major source of .pdf
A sample of 200 people were asked to identify their major source of .pdfarpittradersjdr
 
Prolog programming …Using Amzi Prolog, create and test prolog clau.pdf
Prolog programming …Using Amzi Prolog, create and test prolog clau.pdfProlog programming …Using Amzi Prolog, create and test prolog clau.pdf
Prolog programming …Using Amzi Prolog, create and test prolog clau.pdfarpittradersjdr
 
in java Can we create an object of type Interface Explain your answ.pdf
in java Can we create an object of type Interface Explain your answ.pdfin java Can we create an object of type Interface Explain your answ.pdf
in java Can we create an object of type Interface Explain your answ.pdfarpittradersjdr
 
Implement a client server design using a UDP socket and features of .pdf
Implement a client server design using a UDP socket and features of .pdfImplement a client server design using a UDP socket and features of .pdf
Implement a client server design using a UDP socket and features of .pdfarpittradersjdr
 
I need help in matlab.The task is echo removing from the signal.Supp.pdf
I need help in matlab.The task is echo removing from the signal.Supp.pdfI need help in matlab.The task is echo removing from the signal.Supp.pdf
I need help in matlab.The task is echo removing from the signal.Supp.pdfarpittradersjdr
 
Human language uses less sounds and is less symbolic than are the co.pdf
Human language  uses less sounds and is less symbolic than are the co.pdfHuman language  uses less sounds and is less symbolic than are the co.pdf
Human language uses less sounds and is less symbolic than are the co.pdfarpittradersjdr
 
Genetics homework1. The rut site involved in Rho-dependent termina.pdf
Genetics homework1. The rut site involved in Rho-dependent termina.pdfGenetics homework1. The rut site involved in Rho-dependent termina.pdf
Genetics homework1. The rut site involved in Rho-dependent termina.pdfarpittradersjdr
 
For the segment of code below display the contents of the Array Stack.pdf
For the segment of code below display the contents of the Array Stack.pdfFor the segment of code below display the contents of the Array Stack.pdf
For the segment of code below display the contents of the Array Stack.pdfarpittradersjdr
 
Explain the sources of police subculture. king undercover would affec.pdf
Explain the sources of police subculture. king undercover would affec.pdfExplain the sources of police subculture. king undercover would affec.pdf
Explain the sources of police subculture. king undercover would affec.pdfarpittradersjdr
 

More from arpittradersjdr (20)

When light strikes chlorophyll of photosystem II, a molecule loses el.pdf
When light strikes chlorophyll of photosystem II, a molecule loses el.pdfWhen light strikes chlorophyll of photosystem II, a molecule loses el.pdf
When light strikes chlorophyll of photosystem II, a molecule loses el.pdf
 
You have persuaded XelPharms CIO that wireless networking would be.pdf
You have persuaded XelPharms CIO that wireless networking would be.pdfYou have persuaded XelPharms CIO that wireless networking would be.pdf
You have persuaded XelPharms CIO that wireless networking would be.pdf
 
Where do vesicles come fromA. Plasma membranceB. Nuclear membra.pdf
Where do vesicles come fromA. Plasma membranceB. Nuclear membra.pdfWhere do vesicles come fromA. Plasma membranceB. Nuclear membra.pdf
Where do vesicles come fromA. Plasma membranceB. Nuclear membra.pdf
 
Which of the following are statements 1. She is a mathematics maj.pdf
Which of the following are statements 1. She is a mathematics maj.pdfWhich of the following are statements 1. She is a mathematics maj.pdf
Which of the following are statements 1. She is a mathematics maj.pdf
 
What problem was IETF DiffServ supposed to solve How did IETF DiffS.pdf
What problem was IETF DiffServ supposed to solve  How did IETF DiffS.pdfWhat problem was IETF DiffServ supposed to solve  How did IETF DiffS.pdf
What problem was IETF DiffServ supposed to solve How did IETF DiffS.pdf
 
what causes hydrogen bonds to form between polar moleculesSolut.pdf
what causes hydrogen bonds to form between polar moleculesSolut.pdfwhat causes hydrogen bonds to form between polar moleculesSolut.pdf
what causes hydrogen bonds to form between polar moleculesSolut.pdf
 
What are the four main factors involved in the movement of ions acro.pdf
What are the four main factors involved in the movement of ions acro.pdfWhat are the four main factors involved in the movement of ions acro.pdf
What are the four main factors involved in the movement of ions acro.pdf
 
Transitional epithelium L x) strained columnar epimeeliamL X) Sol.pdf
Transitional epithelium L x) strained columnar epimeeliamL X) Sol.pdfTransitional epithelium L x) strained columnar epimeeliamL X) Sol.pdf
Transitional epithelium L x) strained columnar epimeeliamL X) Sol.pdf
 
The alpha-helix shown below is part of a water-soluble, globular prot.pdf
The alpha-helix shown below is part of a water-soluble, globular prot.pdfThe alpha-helix shown below is part of a water-soluble, globular prot.pdf
The alpha-helix shown below is part of a water-soluble, globular prot.pdf
 
Simple squamous epithelium is structured to best provideA. Diffus.pdf
Simple squamous epithelium is structured to best provideA. Diffus.pdfSimple squamous epithelium is structured to best provideA. Diffus.pdf
Simple squamous epithelium is structured to best provideA. Diffus.pdf
 
A tower leans at an angle of about 84.7°. The figure shows that 150 .pdf
A tower leans at an angle of about 84.7°. The figure shows that 150 .pdfA tower leans at an angle of about 84.7°. The figure shows that 150 .pdf
A tower leans at an angle of about 84.7°. The figure shows that 150 .pdf
 
A sample of 200 people were asked to identify their major source of .pdf
A sample of 200 people were asked to identify their major source of .pdfA sample of 200 people were asked to identify their major source of .pdf
A sample of 200 people were asked to identify their major source of .pdf
 
Prolog programming …Using Amzi Prolog, create and test prolog clau.pdf
Prolog programming …Using Amzi Prolog, create and test prolog clau.pdfProlog programming …Using Amzi Prolog, create and test prolog clau.pdf
Prolog programming …Using Amzi Prolog, create and test prolog clau.pdf
 
in java Can we create an object of type Interface Explain your answ.pdf
in java Can we create an object of type Interface Explain your answ.pdfin java Can we create an object of type Interface Explain your answ.pdf
in java Can we create an object of type Interface Explain your answ.pdf
 
Implement a client server design using a UDP socket and features of .pdf
Implement a client server design using a UDP socket and features of .pdfImplement a client server design using a UDP socket and features of .pdf
Implement a client server design using a UDP socket and features of .pdf
 
I need help in matlab.The task is echo removing from the signal.Supp.pdf
I need help in matlab.The task is echo removing from the signal.Supp.pdfI need help in matlab.The task is echo removing from the signal.Supp.pdf
I need help in matlab.The task is echo removing from the signal.Supp.pdf
 
Human language uses less sounds and is less symbolic than are the co.pdf
Human language  uses less sounds and is less symbolic than are the co.pdfHuman language  uses less sounds and is less symbolic than are the co.pdf
Human language uses less sounds and is less symbolic than are the co.pdf
 
Genetics homework1. The rut site involved in Rho-dependent termina.pdf
Genetics homework1. The rut site involved in Rho-dependent termina.pdfGenetics homework1. The rut site involved in Rho-dependent termina.pdf
Genetics homework1. The rut site involved in Rho-dependent termina.pdf
 
For the segment of code below display the contents of the Array Stack.pdf
For the segment of code below display the contents of the Array Stack.pdfFor the segment of code below display the contents of the Array Stack.pdf
For the segment of code below display the contents of the Array Stack.pdf
 
Explain the sources of police subculture. king undercover would affec.pdf
Explain the sources of police subculture. king undercover would affec.pdfExplain the sources of police subculture. king undercover would affec.pdf
Explain the sources of police subculture. king undercover would affec.pdf
 

Recently uploaded

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 

How to build a Linked List that can insert any type of data. For exa.pdf

  • 1. How to build a Linked List that can insert any type of data. For example: SLinkedList abc1; SLinkedList abc2; SLinkedlist abc3; Please answer in C plus plus, you don't need to develop all function, just insert data is enough. Thank you. Solution #include #include #define LEFT 2 #define RIGHT 3 typedef struct linked_list { double data; struct linked_list *next; }node;//node declaration for single linked list /*function prototype declaration*/ void insertion(node **,double); void erase(node **,node **); //void left_or_right(node **,node **,int); node *makenode(double); void show(node **,node **); /*main*/ int main() { system("clear"); char choice; double item; node *start=NULL,*prev=NULL; do { printf(" =========================== tMENU =========================== t1.Insert t2.Exit Enter your choice :: "); scanf(" %c",&choice); switch(choice)
  • 2. { case '1': printf(" Enter item :: "); scanf("%lf",&item); insertion(&start,item);//insert function calling show(&start,&prev); break; case '2': erase(&prev,&start); printf(" You are exited from the whole program. "); exit(1); default: printf(" tWrong Choice "); } } while(choice!='2'); return 0; } void show(node **start,node **prev)/*this function displays the whole linked list*/ { if((*start)!=NULL) { printf(" X <- "); node *temp=NULL,*p=*prev,*q=NULL; while(p!=NULL) { if(temp==NULL) { temp=makenode(p->data); } else { q=makenode(p->data); q->next=temp; temp=q; }
  • 3. p=p->next; } while(temp!=NULL) { printf("%.0lf <- ",temp->data); q=temp; temp=temp->next; free(q); q=NULL; } printf("b| "); p=*start; while(p!=NULL) { if(p==*start) { printf("%.0lf |-> ",p->data); } else { printf("%.0lf -> ",p->data); } p=p->next; } printf(" X "); } else { printf(" tEmpty Linked List "); } } void insertion(node **start,double item)//this function inserts a new node in the linked list { node *temp=makenode(item),*p=NULL; if(*start==NULL) {
  • 4. *start=temp; } else { p=*start; while(p->next!=NULL) { p=p->next; } p->next=temp; } } node *makenode(double item) { node *temp=NULL; temp=(node *)malloc(sizeof(node)); if(temp==NULL) { printf(" Dynamic memory allocation failed. "); exit(0); } temp->data=item; temp->next=NULL; } void erase(node **prev,node **start)//this function deletes all nodes of the linked list when the program terminates { node *p=NULL; while(*start!=NULL) { p=*start; *start=(*start)->next; free(p); p=NULL; } while(*prev!=NULL)