SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Similaire à 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
 

Similaire à 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...
 

Plus 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
 

Plus 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
 

Dernier

The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
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
 
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
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
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
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
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
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
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
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 

Dernier (20)

The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
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
 
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
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
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 ...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
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
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
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
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
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"
 

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