SlideShare uma empresa Scribd logo
1 de 3
10. Consider the following data structure used for implementing a linked list: struct Node int
data. Node *next; Implement the function that takes a pointer to the first node of a linked list and
an integer value as arguments. It returns -1 if the input value is not equal to the data value of any
item in the list. Otherwise, it returns the location of an item in the list whose data value is equal
to the input value. Assume that the location of the first item in the list is 0. int search List (Node
*head, int value) write the function body
Solution
#include <iostream>
using namespace std;
struct Node{
int data;
Node *next;
};
//inserting element at front side in list
void insert(Node **head,int data){
struct Node *temp;
if(*head==NULL){
(*head)=(struct Node*)malloc(sizeof(struct Node));
(*head)->data=data;
(*head)->next=NULL;
}else{
temp=(struct Node*)malloc(sizeof(struct Node));
temp->data=data;
temp->next=(*head);
(*head)=temp;
}
}
// searching element in list
int searchList(Node *head, int value){
int i=0;int flag=0;
while(head!=NULL){
if(head->data==value){
flag=1;
return i;
}
i++;
head=head->next;
}
if(flag==0)
return -1;
}
void printElement(Node *head){
while(head!=NULL){
cout<<head->data;
head=head->next;
}
}
int main()
{
struct Node *head=NULL;
insert(&head,10);
insert(&head,20);
insert(&head,30);
insert(&head,40);
insert(&head,50);
//printElement(head);
int rValue=searchList(head,30);
if(rValue==-1){
cout<<"Value do not exist in list"<<endl;
}
else{
cout<<"Value exist at position "<<rValue<<endl;
}
return 0;
}
/*sample output*/
searchList(head,30);
Value exist at 2
searchList(head,60);
Value do not exist in list
10- Consider the following data structure used for implementing a link.docx

Mais conteúdo relacionado

Semelhante a 10- Consider the following data structure used for implementing a link.docx

Write an algorithm that reads a list of integers from the keyboard, .pdf
Write an algorithm that reads a list of integers from the keyboard, .pdfWrite an algorithm that reads a list of integers from the keyboard, .pdf
Write an algorithm that reads a list of integers from the keyboard, .pdfArrowdeepak
 
1#include stdio.h#include stdlib.h#include assert.h .pdf
1#include stdio.h#include stdlib.h#include assert.h .pdf1#include stdio.h#include stdlib.h#include assert.h .pdf
1#include stdio.h#include stdlib.h#include assert.h .pdfsudhinjv
 
please help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdfplease help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdfaminbijal86
 
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
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfrozakashif85
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptxchin463670
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfannaelctronics
 
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
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfarchgeetsenterprises
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfmalavshah9013
 
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
 

Semelhante a 10- Consider the following data structure used for implementing a link.docx (20)

Adt of lists
Adt of listsAdt of lists
Adt of lists
 
Write an algorithm that reads a list of integers from the keyboard, .pdf
Write an algorithm that reads a list of integers from the keyboard, .pdfWrite an algorithm that reads a list of integers from the keyboard, .pdf
Write an algorithm that reads a list of integers from the keyboard, .pdf
 
Linked List.pptx
Linked List.pptxLinked List.pptx
Linked List.pptx
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
1#include stdio.h#include stdlib.h#include assert.h .pdf
1#include stdio.h#include stdlib.h#include assert.h .pdf1#include stdio.h#include stdlib.h#include assert.h .pdf
1#include stdio.h#include stdlib.h#include assert.h .pdf
 
please help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdfplease help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.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
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
 
C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptx
 
Ll.pptx
Ll.pptxLl.pptx
Ll.pptx
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.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
 
Unit II Data Structure 2hr topic - List - Operations.pptx
Unit II  Data Structure 2hr topic - List - Operations.pptxUnit II  Data Structure 2hr topic - List - Operations.pptx
Unit II Data Structure 2hr topic - List - Operations.pptx
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
 
Linked list
Linked listLinked list
Linked list
 
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...
 

Mais de todd991

14- Which of the following is the correct name for NalICO- A- Sodiuns.docx
14- Which of the following is the correct name for NalICO- A- Sodiuns.docx14- Which of the following is the correct name for NalICO- A- Sodiuns.docx
14- Which of the following is the correct name for NalICO- A- Sodiuns.docxtodd991
 
14 Income tax is estimated at 40- of income- What factors other than e.docx
14 Income tax is estimated at 40- of income- What factors other than e.docx14 Income tax is estimated at 40- of income- What factors other than e.docx
14 Income tax is estimated at 40- of income- What factors other than e.docxtodd991
 
12-19 Notes Compare and contrast the Hubble Space Telescope with James.docx
12-19 Notes Compare and contrast the Hubble Space Telescope with James.docx12-19 Notes Compare and contrast the Hubble Space Telescope with James.docx
12-19 Notes Compare and contrast the Hubble Space Telescope with James.docxtodd991
 
12-5 Distribution of Cash Upon Liquidation Manley and Singh are partne.docx
12-5 Distribution of Cash Upon Liquidation Manley and Singh are partne.docx12-5 Distribution of Cash Upon Liquidation Manley and Singh are partne.docx
12-5 Distribution of Cash Upon Liquidation Manley and Singh are partne.docxtodd991
 
10 Solution#include-iostream-h- #include-conio-h- #include-process-h-.docx
10 Solution#include-iostream-h- #include-conio-h- #include-process-h-.docx10 Solution#include-iostream-h- #include-conio-h- #include-process-h-.docx
10 Solution#include-iostream-h- #include-conio-h- #include-process-h-.docxtodd991
 
1-What are the consequences of long term unemployment- 2-Should the go.docx
1-What are the consequences of long term unemployment- 2-Should the go.docx1-What are the consequences of long term unemployment- 2-Should the go.docx
1-What are the consequences of long term unemployment- 2-Should the go.docxtodd991
 
1-What is the conjugate base of H2C2O4- 2-Which of the following acid.docx
1-What is the conjugate base of H2C2O4-  2-Which of the following acid.docx1-What is the conjugate base of H2C2O4-  2-Which of the following acid.docx
1-What is the conjugate base of H2C2O4- 2-Which of the following acid.docxtodd991
 
1-The fund financial statements for governmental funds should include.docx
1-The fund financial statements for governmental funds should include.docx1-The fund financial statements for governmental funds should include.docx
1-The fund financial statements for governmental funds should include.docxtodd991
 
1-To a young researcher- what are the advantages of using the method o.docx
1-To a young researcher- what are the advantages of using the method o.docx1-To a young researcher- what are the advantages of using the method o.docx
1-To a young researcher- what are the advantages of using the method o.docxtodd991
 
1-The party to receive a distribution of principal from an estate is l.docx
1-The party to receive a distribution of principal from an estate is l.docx1-The party to receive a distribution of principal from an estate is l.docx
1-The party to receive a distribution of principal from an estate is l.docxtodd991
 
1-Consider an organization with which you have been affiliated as an e.docx
1-Consider an organization with which you have been affiliated as an e.docx1-Consider an organization with which you have been affiliated as an e.docx
1-Consider an organization with which you have been affiliated as an e.docxtodd991
 
1-Astronomers estimate that a low-mass red dwarf star like Proxima Cen.docx
1-Astronomers estimate that a low-mass red dwarf star like Proxima Cen.docx1-Astronomers estimate that a low-mass red dwarf star like Proxima Cen.docx
1-Astronomers estimate that a low-mass red dwarf star like Proxima Cen.docxtodd991
 
1-a Which of TCP or UDP is connection-less- Which of TCP or UDP is con.docx
1-a Which of TCP or UDP is connection-less- Which of TCP or UDP is con.docx1-a Which of TCP or UDP is connection-less- Which of TCP or UDP is con.docx
1-a Which of TCP or UDP is connection-less- Which of TCP or UDP is con.docxtodd991
 
1- You align 2 lenses together with known focal lengths fi and fa- The.docx
1- You align 2 lenses together with known focal lengths fi and fa- The.docx1- You align 2 lenses together with known focal lengths fi and fa- The.docx
1- You align 2 lenses together with known focal lengths fi and fa- The.docxtodd991
 
1- What were some of the major work published by Thomas Maithus- emplo.docx
1- What were some of the major work published by Thomas Maithus- emplo.docx1- What were some of the major work published by Thomas Maithus- emplo.docx
1- What were some of the major work published by Thomas Maithus- emplo.docxtodd991
 
1- What are the advantages and disadvantages of each of sociologys mai.docx
1- What are the advantages and disadvantages of each of sociologys mai.docx1- What are the advantages and disadvantages of each of sociologys mai.docx
1- What are the advantages and disadvantages of each of sociologys mai.docxtodd991
 
1- What are the three fundamental elements of an effective security pr.docx
1- What are the three fundamental elements of an effective security pr.docx1- What are the three fundamental elements of an effective security pr.docx
1- What are the three fundamental elements of an effective security pr.docxtodd991
 
1- What are the various theories that we use to explain why people com.docx
1- What are the various theories that we use to explain why people com.docx1- What are the various theories that we use to explain why people com.docx
1- What are the various theories that we use to explain why people com.docxtodd991
 
1- Return the names- IDS- and average salary of the top 10 employees w.docx
1- Return the names- IDS- and average salary of the top 10 employees w.docx1- Return the names- IDS- and average salary of the top 10 employees w.docx
1- Return the names- IDS- and average salary of the top 10 employees w.docxtodd991
 
1- Research has shown that a- homogeneous groups are more creative tha.docx
1- Research has shown that a- homogeneous groups are more creative tha.docx1- Research has shown that a- homogeneous groups are more creative tha.docx
1- Research has shown that a- homogeneous groups are more creative tha.docxtodd991
 

Mais de todd991 (20)

14- Which of the following is the correct name for NalICO- A- Sodiuns.docx
14- Which of the following is the correct name for NalICO- A- Sodiuns.docx14- Which of the following is the correct name for NalICO- A- Sodiuns.docx
14- Which of the following is the correct name for NalICO- A- Sodiuns.docx
 
14 Income tax is estimated at 40- of income- What factors other than e.docx
14 Income tax is estimated at 40- of income- What factors other than e.docx14 Income tax is estimated at 40- of income- What factors other than e.docx
14 Income tax is estimated at 40- of income- What factors other than e.docx
 
12-19 Notes Compare and contrast the Hubble Space Telescope with James.docx
12-19 Notes Compare and contrast the Hubble Space Telescope with James.docx12-19 Notes Compare and contrast the Hubble Space Telescope with James.docx
12-19 Notes Compare and contrast the Hubble Space Telescope with James.docx
 
12-5 Distribution of Cash Upon Liquidation Manley and Singh are partne.docx
12-5 Distribution of Cash Upon Liquidation Manley and Singh are partne.docx12-5 Distribution of Cash Upon Liquidation Manley and Singh are partne.docx
12-5 Distribution of Cash Upon Liquidation Manley and Singh are partne.docx
 
10 Solution#include-iostream-h- #include-conio-h- #include-process-h-.docx
10 Solution#include-iostream-h- #include-conio-h- #include-process-h-.docx10 Solution#include-iostream-h- #include-conio-h- #include-process-h-.docx
10 Solution#include-iostream-h- #include-conio-h- #include-process-h-.docx
 
1-What are the consequences of long term unemployment- 2-Should the go.docx
1-What are the consequences of long term unemployment- 2-Should the go.docx1-What are the consequences of long term unemployment- 2-Should the go.docx
1-What are the consequences of long term unemployment- 2-Should the go.docx
 
1-What is the conjugate base of H2C2O4- 2-Which of the following acid.docx
1-What is the conjugate base of H2C2O4-  2-Which of the following acid.docx1-What is the conjugate base of H2C2O4-  2-Which of the following acid.docx
1-What is the conjugate base of H2C2O4- 2-Which of the following acid.docx
 
1-The fund financial statements for governmental funds should include.docx
1-The fund financial statements for governmental funds should include.docx1-The fund financial statements for governmental funds should include.docx
1-The fund financial statements for governmental funds should include.docx
 
1-To a young researcher- what are the advantages of using the method o.docx
1-To a young researcher- what are the advantages of using the method o.docx1-To a young researcher- what are the advantages of using the method o.docx
1-To a young researcher- what are the advantages of using the method o.docx
 
1-The party to receive a distribution of principal from an estate is l.docx
1-The party to receive a distribution of principal from an estate is l.docx1-The party to receive a distribution of principal from an estate is l.docx
1-The party to receive a distribution of principal from an estate is l.docx
 
1-Consider an organization with which you have been affiliated as an e.docx
1-Consider an organization with which you have been affiliated as an e.docx1-Consider an organization with which you have been affiliated as an e.docx
1-Consider an organization with which you have been affiliated as an e.docx
 
1-Astronomers estimate that a low-mass red dwarf star like Proxima Cen.docx
1-Astronomers estimate that a low-mass red dwarf star like Proxima Cen.docx1-Astronomers estimate that a low-mass red dwarf star like Proxima Cen.docx
1-Astronomers estimate that a low-mass red dwarf star like Proxima Cen.docx
 
1-a Which of TCP or UDP is connection-less- Which of TCP or UDP is con.docx
1-a Which of TCP or UDP is connection-less- Which of TCP or UDP is con.docx1-a Which of TCP or UDP is connection-less- Which of TCP or UDP is con.docx
1-a Which of TCP or UDP is connection-less- Which of TCP or UDP is con.docx
 
1- You align 2 lenses together with known focal lengths fi and fa- The.docx
1- You align 2 lenses together with known focal lengths fi and fa- The.docx1- You align 2 lenses together with known focal lengths fi and fa- The.docx
1- You align 2 lenses together with known focal lengths fi and fa- The.docx
 
1- What were some of the major work published by Thomas Maithus- emplo.docx
1- What were some of the major work published by Thomas Maithus- emplo.docx1- What were some of the major work published by Thomas Maithus- emplo.docx
1- What were some of the major work published by Thomas Maithus- emplo.docx
 
1- What are the advantages and disadvantages of each of sociologys mai.docx
1- What are the advantages and disadvantages of each of sociologys mai.docx1- What are the advantages and disadvantages of each of sociologys mai.docx
1- What are the advantages and disadvantages of each of sociologys mai.docx
 
1- What are the three fundamental elements of an effective security pr.docx
1- What are the three fundamental elements of an effective security pr.docx1- What are the three fundamental elements of an effective security pr.docx
1- What are the three fundamental elements of an effective security pr.docx
 
1- What are the various theories that we use to explain why people com.docx
1- What are the various theories that we use to explain why people com.docx1- What are the various theories that we use to explain why people com.docx
1- What are the various theories that we use to explain why people com.docx
 
1- Return the names- IDS- and average salary of the top 10 employees w.docx
1- Return the names- IDS- and average salary of the top 10 employees w.docx1- Return the names- IDS- and average salary of the top 10 employees w.docx
1- Return the names- IDS- and average salary of the top 10 employees w.docx
 
1- Research has shown that a- homogeneous groups are more creative tha.docx
1- Research has shown that a- homogeneous groups are more creative tha.docx1- Research has shown that a- homogeneous groups are more creative tha.docx
1- Research has shown that a- homogeneous groups are more creative tha.docx
 

Último

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 

Último (20)

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

10- Consider the following data structure used for implementing a link.docx

  • 1. 10. Consider the following data structure used for implementing a linked list: struct Node int data. Node *next; Implement the function that takes a pointer to the first node of a linked list and an integer value as arguments. It returns -1 if the input value is not equal to the data value of any item in the list. Otherwise, it returns the location of an item in the list whose data value is equal to the input value. Assume that the location of the first item in the list is 0. int search List (Node *head, int value) write the function body Solution #include <iostream> using namespace std; struct Node{ int data; Node *next; }; //inserting element at front side in list void insert(Node **head,int data){ struct Node *temp; if(*head==NULL){ (*head)=(struct Node*)malloc(sizeof(struct Node)); (*head)->data=data; (*head)->next=NULL; }else{ temp=(struct Node*)malloc(sizeof(struct Node)); temp->data=data; temp->next=(*head); (*head)=temp; } } // searching element in list int searchList(Node *head, int value){ int i=0;int flag=0; while(head!=NULL){ if(head->data==value){ flag=1;
  • 2. return i; } i++; head=head->next; } if(flag==0) return -1; } void printElement(Node *head){ while(head!=NULL){ cout<<head->data; head=head->next; } } int main() { struct Node *head=NULL; insert(&head,10); insert(&head,20); insert(&head,30); insert(&head,40); insert(&head,50); //printElement(head); int rValue=searchList(head,30); if(rValue==-1){ cout<<"Value do not exist in list"<<endl; } else{ cout<<"Value exist at position "<<rValue<<endl; } return 0; } /*sample output*/ searchList(head,30); Value exist at 2 searchList(head,60); Value do not exist in list