SlideShare uma empresa Scribd logo
1 de 2
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 searchList(Node *head, int value) {
// write the function body
Solution
Example of seeking the position of an item in a list
int searchList(Node *head, int value) {
Node *temp; // temportal Variable of node of the head of the list
temp = head; // copy the top of the list
int pos = 0; // We initialize the return value if you find the item in any position from the list
while(temp){ // verify that while null is different from the temporary variable will check the
items
// if the item in the list is equal to the value we return sought the position in which it was found
if (temp->data == value)
return pos; // we return the position
pos++; // while we do not get the items we continue down the list
temp = temp->next;
}
return -1; // if we do not find the item in the list we return -1
}

Mais conteúdo relacionado

Semelhante a Find list item position by value

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
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptxchin463670
 
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdfHomework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdfezzi97
 
Implement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdfImplement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdfudit652068
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfxlynettalampleyxc
 
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
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfezonesolutions
 
Linked list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversalkasthurimukila
 
Design, implement, test(In Java ) a doubly linked list ADT, using DL.pdf
Design, implement, test(In Java ) a doubly linked list ADT, using DL.pdfDesign, implement, test(In Java ) a doubly linked list ADT, using DL.pdf
Design, implement, test(In Java ) a doubly linked list ADT, using DL.pdftrishacolsyn25353
 
JAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdf
JAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdfJAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdf
JAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdfsuresh640714
 
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdfImplement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdfrishabjain5053
 
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfimplement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfFOREVERPRODUCTCHD
 
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
 
Template LinkedList;I am using templates to make some linkedLists.pdf
Template LinkedList;I am using templates to make some linkedLists.pdfTemplate LinkedList;I am using templates to make some linkedLists.pdf
Template LinkedList;I am using templates to make some linkedLists.pdffatoryoutlets
 

Semelhante a Find list item position by value (20)

Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
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
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptx
 
Ll.pptx
Ll.pptxLl.pptx
Ll.pptx
 
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdfHomework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
 
Implement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdfImplement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdf
 
강의자료9
강의자료9강의자료9
강의자료9
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
 
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
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdf
 
Linked list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversal
 
Linked list1
Linked list1Linked list1
Linked list1
 
Design, implement, test(In Java ) a doubly linked list ADT, using DL.pdf
Design, implement, test(In Java ) a doubly linked list ADT, using DL.pdfDesign, implement, test(In Java ) a doubly linked list ADT, using DL.pdf
Design, implement, test(In Java ) a doubly linked list ADT, using DL.pdf
 
JAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdf
JAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdfJAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdf
JAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdf
 
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdfImplement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
 
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfimplement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
 
Ds notes
Ds notesDs notes
Ds notes
 
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
 
Template LinkedList;I am using templates to make some linkedLists.pdf
Template LinkedList;I am using templates to make some linkedLists.pdfTemplate LinkedList;I am using templates to make some linkedLists.pdf
Template LinkedList;I am using templates to make some linkedLists.pdf
 

Mais de kaseya1

A number of monks live in a monastery and they do not communicate in a.docx
A number of monks live in a monastery and they do not communicate in a.docxA number of monks live in a monastery and they do not communicate in a.docx
A number of monks live in a monastery and they do not communicate in a.docxkaseya1
 
A molecule or ion that donates the hydrogen in a hydrogen bond is a hy (1).docx
A molecule or ion that donates the hydrogen in a hydrogen bond is a hy (1).docxA molecule or ion that donates the hydrogen in a hydrogen bond is a hy (1).docx
A molecule or ion that donates the hydrogen in a hydrogen bond is a hy (1).docxkaseya1
 
A person talking produces a sound level of 65 dB at a distance of 50 c.docx
A person talking produces a sound level of 65 dB at a distance of 50 c.docxA person talking produces a sound level of 65 dB at a distance of 50 c.docx
A person talking produces a sound level of 65 dB at a distance of 50 c.docxkaseya1
 
A metal plate is illuminated with light of a certain frequency- Which.docx
A metal plate is illuminated with light of a certain frequency- Which.docxA metal plate is illuminated with light of a certain frequency- Which.docx
A metal plate is illuminated with light of a certain frequency- Which.docxkaseya1
 
A Martian leaves Mars in a spaceship that is heading to Venus- On the.docx
A Martian leaves Mars in a spaceship that is heading to Venus- On the.docxA Martian leaves Mars in a spaceship that is heading to Venus- On the.docx
A Martian leaves Mars in a spaceship that is heading to Venus- On the.docxkaseya1
 
a major change in our study of differing economic systems in the era o.docx
a major change in our study of differing economic systems in the era o.docxa major change in our study of differing economic systems in the era o.docx
a major change in our study of differing economic systems in the era o.docxkaseya1
 
A leadership-motivation case is provided below- The case includes impo.docx
A leadership-motivation case is provided below- The case includes impo.docxA leadership-motivation case is provided below- The case includes impo.docx
A leadership-motivation case is provided below- The case includes impo.docxkaseya1
 
A kettle is filled with tap water and placed on a stove- The stove ele.docx
A kettle is filled with tap water and placed on a stove- The stove ele.docxA kettle is filled with tap water and placed on a stove- The stove ele.docx
A kettle is filled with tap water and placed on a stove- The stove ele.docxkaseya1
 
A photographer works part-time in a shopping center- 2 hours per day-.docx
A photographer works part-time in a shopping center- 2 hours per day-.docxA photographer works part-time in a shopping center- 2 hours per day-.docx
A photographer works part-time in a shopping center- 2 hours per day-.docxkaseya1
 
Consider the following definitions for linked lists for problems 6 thr.docx
Consider the following definitions for linked lists for problems 6 thr.docxConsider the following definitions for linked lists for problems 6 thr.docx
Consider the following definitions for linked lists for problems 6 thr.docxkaseya1
 
Consider the following chemical compounds- Classify each as either an.docx
Consider the following chemical compounds- Classify each as either an.docxConsider the following chemical compounds- Classify each as either an.docx
Consider the following chemical compounds- Classify each as either an.docxkaseya1
 
Consider the plane R2 and consider any two lines that pass through the.docx
Consider the plane R2 and consider any two lines that pass through the.docxConsider the plane R2 and consider any two lines that pass through the.docx
Consider the plane R2 and consider any two lines that pass through the.docxkaseya1
 
Consider the following statements about the investment in working capi.docx
Consider the following statements about the investment in working capi.docxConsider the following statements about the investment in working capi.docx
Consider the following statements about the investment in working capi.docxkaseya1
 
Consider the following method definitions intended to find the smalles.docx
Consider the following method definitions intended to find the smalles.docxConsider the following method definitions intended to find the smalles.docx
Consider the following method definitions intended to find the smalles.docxkaseya1
 
Consider relations R and S as following and answer question- R A B 1 2 (8).docx
Consider relations R and S as following and answer question- R A B 1 2 (8).docxConsider relations R and S as following and answer question- R A B 1 2 (8).docx
Consider relations R and S as following and answer question- R A B 1 2 (8).docxkaseya1
 

Mais de kaseya1 (15)

A number of monks live in a monastery and they do not communicate in a.docx
A number of monks live in a monastery and they do not communicate in a.docxA number of monks live in a monastery and they do not communicate in a.docx
A number of monks live in a monastery and they do not communicate in a.docx
 
A molecule or ion that donates the hydrogen in a hydrogen bond is a hy (1).docx
A molecule or ion that donates the hydrogen in a hydrogen bond is a hy (1).docxA molecule or ion that donates the hydrogen in a hydrogen bond is a hy (1).docx
A molecule or ion that donates the hydrogen in a hydrogen bond is a hy (1).docx
 
A person talking produces a sound level of 65 dB at a distance of 50 c.docx
A person talking produces a sound level of 65 dB at a distance of 50 c.docxA person talking produces a sound level of 65 dB at a distance of 50 c.docx
A person talking produces a sound level of 65 dB at a distance of 50 c.docx
 
A metal plate is illuminated with light of a certain frequency- Which.docx
A metal plate is illuminated with light of a certain frequency- Which.docxA metal plate is illuminated with light of a certain frequency- Which.docx
A metal plate is illuminated with light of a certain frequency- Which.docx
 
A Martian leaves Mars in a spaceship that is heading to Venus- On the.docx
A Martian leaves Mars in a spaceship that is heading to Venus- On the.docxA Martian leaves Mars in a spaceship that is heading to Venus- On the.docx
A Martian leaves Mars in a spaceship that is heading to Venus- On the.docx
 
a major change in our study of differing economic systems in the era o.docx
a major change in our study of differing economic systems in the era o.docxa major change in our study of differing economic systems in the era o.docx
a major change in our study of differing economic systems in the era o.docx
 
A leadership-motivation case is provided below- The case includes impo.docx
A leadership-motivation case is provided below- The case includes impo.docxA leadership-motivation case is provided below- The case includes impo.docx
A leadership-motivation case is provided below- The case includes impo.docx
 
A kettle is filled with tap water and placed on a stove- The stove ele.docx
A kettle is filled with tap water and placed on a stove- The stove ele.docxA kettle is filled with tap water and placed on a stove- The stove ele.docx
A kettle is filled with tap water and placed on a stove- The stove ele.docx
 
A photographer works part-time in a shopping center- 2 hours per day-.docx
A photographer works part-time in a shopping center- 2 hours per day-.docxA photographer works part-time in a shopping center- 2 hours per day-.docx
A photographer works part-time in a shopping center- 2 hours per day-.docx
 
Consider the following definitions for linked lists for problems 6 thr.docx
Consider the following definitions for linked lists for problems 6 thr.docxConsider the following definitions for linked lists for problems 6 thr.docx
Consider the following definitions for linked lists for problems 6 thr.docx
 
Consider the following chemical compounds- Classify each as either an.docx
Consider the following chemical compounds- Classify each as either an.docxConsider the following chemical compounds- Classify each as either an.docx
Consider the following chemical compounds- Classify each as either an.docx
 
Consider the plane R2 and consider any two lines that pass through the.docx
Consider the plane R2 and consider any two lines that pass through the.docxConsider the plane R2 and consider any two lines that pass through the.docx
Consider the plane R2 and consider any two lines that pass through the.docx
 
Consider the following statements about the investment in working capi.docx
Consider the following statements about the investment in working capi.docxConsider the following statements about the investment in working capi.docx
Consider the following statements about the investment in working capi.docx
 
Consider the following method definitions intended to find the smalles.docx
Consider the following method definitions intended to find the smalles.docxConsider the following method definitions intended to find the smalles.docx
Consider the following method definitions intended to find the smalles.docx
 
Consider relations R and S as following and answer question- R A B 1 2 (8).docx
Consider relations R and S as following and answer question- R A B 1 2 (8).docxConsider relations R and S as following and answer question- R A B 1 2 (8).docx
Consider relations R and S as following and answer question- R A B 1 2 (8).docx
 

Último

MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsManeerUddin
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 

Último (20)

MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture hons
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 

Find list item position by value

  • 1. 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 searchList(Node *head, int value) { // write the function body Solution Example of seeking the position of an item in a list int searchList(Node *head, int value) { Node *temp; // temportal Variable of node of the head of the list temp = head; // copy the top of the list int pos = 0; // We initialize the return value if you find the item in any position from the list while(temp){ // verify that while null is different from the temporary variable will check the items // if the item in the list is equal to the value we return sought the position in which it was found if (temp->data == value) return pos; // we return the position pos++; // while we do not get the items we continue down the list temp = temp->next; }
  • 2. return -1; // if we do not find the item in the list we return -1 }