SlideShare a Scribd company logo
1 of 2
Download to read offline
Implement the findPre function of the LinkedList class .
Node * LinkedList::findPre(int d)
The job of this function is to return a pointer to the node the precedes a node with data equal to d.
If d only occurs in the head node or d doesn't occur in any node, then the function should return
a pointer to the last node in the list. If the list is empty then the function should return the null
pointer.
This is my current attemp, it is incorrect
Node * LinkedList::findPre(int d){
Node * pre = headPtr;
for (int i = 1; i < position-1; i++)
pre = pre->next;
// how pre points to the node right before the one we want to remove.
Node *temp = pre->next;
pre->next = temp->next;
}
Solution
HI, Please find my implementation.
Please let me know in case of any issue.
Node * LinkedList::findPre(int d){
if(headPtr == NULL)
return NULL;
// if there is only one node(the first and last node is same), then return headPtr (last node)
if(headPtr->next == NULL)
return headPtr;
Node *pre = headPtr;
Node *current = headPtr->next;
while(current != NULL){
if(current->data == d)
return pre;
pre = current;
current = current->next;
}
return pre; // returning last node
}

More Related Content

Similar to Implement the findPre function of the LinkedList class .Node Lin.pdf

singly link list project in dsa.....by rohit malav
singly link list project in dsa.....by rohit malavsingly link list project in dsa.....by rohit malav
singly link list project in dsa.....by rohit malavRohit malav
 
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
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfinfo430661
 
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
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfarrowmobile
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfbabitasingh698417
 
Using the following definition for a Binary Tree Node - complete the f.docx
Using the following definition for a Binary Tree Node - complete the f.docxUsing the following definition for a Binary Tree Node - complete the f.docx
Using the following definition for a Binary Tree Node - complete the f.docxslyndon
 
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
 
For the code below complete the preOrder() method so that it perform.pdf
For the code below complete the preOrder() method so that it perform.pdfFor the code below complete the preOrder() method so that it perform.pdf
For the code below complete the preOrder() method so that it perform.pdfxlynettalampleyxc
 
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdfAssignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdfFootageetoffe16
 
Java AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfJava AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfambersushil
 
Note- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxNote- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxVictorzH8Bondx
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfStewart29UReesa
 
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
 

Similar to Implement the findPre function of the LinkedList class .Node Lin.pdf (20)

singly link list project in dsa.....by rohit malav
singly link list project in dsa.....by rohit malavsingly link list project in dsa.....by rohit malav
singly link list project in dsa.....by rohit malav
 
Linked list
Linked list Linked list
Linked list
 
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
 
Ds notes
Ds notesDs notes
Ds notes
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.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
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
 
Using the following definition for a Binary Tree Node - complete the f.docx
Using the following definition for a Binary Tree Node - complete the f.docxUsing the following definition for a Binary Tree Node - complete the f.docx
Using the following definition for a Binary Tree Node - complete the f.docx
 
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
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
 
For the code below complete the preOrder() method so that it perform.pdf
For the code below complete the preOrder() method so that it perform.pdfFor the code below complete the preOrder() method so that it perform.pdf
For the code below complete the preOrder() method so that it perform.pdf
 
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdfAssignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
 
Java AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfJava AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdf
 
List
ListList
List
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
Note- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxNote- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docx
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
 
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
 

More from shahidqamar17

At one time, the country of Aquilonia had no banks, but had curre.pdf
At one time, the country of Aquilonia had no banks, but had curre.pdfAt one time, the country of Aquilonia had no banks, but had curre.pdf
At one time, the country of Aquilonia had no banks, but had curre.pdfshahidqamar17
 
A certain element has a half life of 4.5 billion years. a. You find .pdf
A certain element has a half life of 4.5 billion years. a. You find .pdfA certain element has a half life of 4.5 billion years. a. You find .pdf
A certain element has a half life of 4.5 billion years. a. You find .pdfshahidqamar17
 
A linear system is always time-invariant.SolutionNo its false. .pdf
A linear system is always time-invariant.SolutionNo its false. .pdfA linear system is always time-invariant.SolutionNo its false. .pdf
A linear system is always time-invariant.SolutionNo its false. .pdfshahidqamar17
 
Workforce Management also called Human Resource Management manages o.pdf
Workforce Management also called Human Resource Management manages o.pdfWorkforce Management also called Human Resource Management manages o.pdf
Workforce Management also called Human Resource Management manages o.pdfshahidqamar17
 
Where has healthcare information management been historically How h.pdf
Where has healthcare information management been historically How h.pdfWhere has healthcare information management been historically How h.pdf
Where has healthcare information management been historically How h.pdfshahidqamar17
 
What were the successes and failures of the Progressive Movement, an.pdf
What were the successes and failures of the Progressive Movement, an.pdfWhat were the successes and failures of the Progressive Movement, an.pdf
What were the successes and failures of the Progressive Movement, an.pdfshahidqamar17
 
What is the difference between private sector, nonprofit sector, and.pdf
What is the difference between private sector, nonprofit sector, and.pdfWhat is the difference between private sector, nonprofit sector, and.pdf
What is the difference between private sector, nonprofit sector, and.pdfshahidqamar17
 
What are Cubas entrepreneurial opportunities and the status of .pdf
What are Cubas entrepreneurial opportunities and the status of .pdfWhat are Cubas entrepreneurial opportunities and the status of .pdf
What are Cubas entrepreneurial opportunities and the status of .pdfshahidqamar17
 
The LabVIEW G programming is considered to be a data flow programmin.pdf
The LabVIEW G programming is considered to be a data flow programmin.pdfThe LabVIEW G programming is considered to be a data flow programmin.pdf
The LabVIEW G programming is considered to be a data flow programmin.pdfshahidqamar17
 
what is a bottom heap up construction with an example pleaseSol.pdf
what is a bottom heap up construction with an example pleaseSol.pdfwhat is a bottom heap up construction with an example pleaseSol.pdf
what is a bottom heap up construction with an example pleaseSol.pdfshahidqamar17
 
What are the types of differences that exist between IFRS and U.S. G.pdf
What are the types of differences that exist between IFRS and U.S. G.pdfWhat are the types of differences that exist between IFRS and U.S. G.pdf
What are the types of differences that exist between IFRS and U.S. G.pdfshahidqamar17
 
ROT13 (rotate by 13 places) is a simple letter substitution cipher t.pdf
ROT13 (rotate by 13 places) is a simple letter substitution cipher t.pdfROT13 (rotate by 13 places) is a simple letter substitution cipher t.pdf
ROT13 (rotate by 13 places) is a simple letter substitution cipher t.pdfshahidqamar17
 
question.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdfquestion.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdfshahidqamar17
 
Question 25 A Multilateral agreement in which countries signed to ban.pdf
Question 25 A Multilateral agreement in which countries signed to ban.pdfQuestion 25 A Multilateral agreement in which countries signed to ban.pdf
Question 25 A Multilateral agreement in which countries signed to ban.pdfshahidqamar17
 
Prove. Let n be a natural number. Any set of n integers {a1, a2, . ..pdf
Prove. Let n be a natural number. Any set of n integers {a1, a2, . ..pdfProve. Let n be a natural number. Any set of n integers {a1, a2, . ..pdf
Prove. Let n be a natural number. Any set of n integers {a1, a2, . ..pdfshahidqamar17
 
1Write a Java program that calculates and displays the Fibonacciseri.pdf
1Write a Java program that calculates and displays the Fibonacciseri.pdf1Write a Java program that calculates and displays the Fibonacciseri.pdf
1Write a Java program that calculates and displays the Fibonacciseri.pdfshahidqamar17
 
need an example of a System Anaysis and design project must have 3 .pdf
need an example of a System Anaysis and design project must have 3 .pdfneed an example of a System Anaysis and design project must have 3 .pdf
need an example of a System Anaysis and design project must have 3 .pdfshahidqamar17
 
Money laundering has become a mechanism for terrorist financing acti.pdf
Money laundering has become a mechanism for terrorist financing acti.pdfMoney laundering has become a mechanism for terrorist financing acti.pdf
Money laundering has become a mechanism for terrorist financing acti.pdfshahidqamar17
 
Let x be any set and let lambda SolutionProof. Obviously .pdf
Let x be any set and let lambda SolutionProof. Obviously .pdfLet x be any set and let lambda SolutionProof. Obviously .pdf
Let x be any set and let lambda SolutionProof. Obviously .pdfshahidqamar17
 
Java public cts Node t next ni next SolutionYou hav.pdf
Java public cts Node t next ni next SolutionYou hav.pdfJava public cts Node t next ni next SolutionYou hav.pdf
Java public cts Node t next ni next SolutionYou hav.pdfshahidqamar17
 

More from shahidqamar17 (20)

At one time, the country of Aquilonia had no banks, but had curre.pdf
At one time, the country of Aquilonia had no banks, but had curre.pdfAt one time, the country of Aquilonia had no banks, but had curre.pdf
At one time, the country of Aquilonia had no banks, but had curre.pdf
 
A certain element has a half life of 4.5 billion years. a. You find .pdf
A certain element has a half life of 4.5 billion years. a. You find .pdfA certain element has a half life of 4.5 billion years. a. You find .pdf
A certain element has a half life of 4.5 billion years. a. You find .pdf
 
A linear system is always time-invariant.SolutionNo its false. .pdf
A linear system is always time-invariant.SolutionNo its false. .pdfA linear system is always time-invariant.SolutionNo its false. .pdf
A linear system is always time-invariant.SolutionNo its false. .pdf
 
Workforce Management also called Human Resource Management manages o.pdf
Workforce Management also called Human Resource Management manages o.pdfWorkforce Management also called Human Resource Management manages o.pdf
Workforce Management also called Human Resource Management manages o.pdf
 
Where has healthcare information management been historically How h.pdf
Where has healthcare information management been historically How h.pdfWhere has healthcare information management been historically How h.pdf
Where has healthcare information management been historically How h.pdf
 
What were the successes and failures of the Progressive Movement, an.pdf
What were the successes and failures of the Progressive Movement, an.pdfWhat were the successes and failures of the Progressive Movement, an.pdf
What were the successes and failures of the Progressive Movement, an.pdf
 
What is the difference between private sector, nonprofit sector, and.pdf
What is the difference between private sector, nonprofit sector, and.pdfWhat is the difference between private sector, nonprofit sector, and.pdf
What is the difference between private sector, nonprofit sector, and.pdf
 
What are Cubas entrepreneurial opportunities and the status of .pdf
What are Cubas entrepreneurial opportunities and the status of .pdfWhat are Cubas entrepreneurial opportunities and the status of .pdf
What are Cubas entrepreneurial opportunities and the status of .pdf
 
The LabVIEW G programming is considered to be a data flow programmin.pdf
The LabVIEW G programming is considered to be a data flow programmin.pdfThe LabVIEW G programming is considered to be a data flow programmin.pdf
The LabVIEW G programming is considered to be a data flow programmin.pdf
 
what is a bottom heap up construction with an example pleaseSol.pdf
what is a bottom heap up construction with an example pleaseSol.pdfwhat is a bottom heap up construction with an example pleaseSol.pdf
what is a bottom heap up construction with an example pleaseSol.pdf
 
What are the types of differences that exist between IFRS and U.S. G.pdf
What are the types of differences that exist between IFRS and U.S. G.pdfWhat are the types of differences that exist between IFRS and U.S. G.pdf
What are the types of differences that exist between IFRS and U.S. G.pdf
 
ROT13 (rotate by 13 places) is a simple letter substitution cipher t.pdf
ROT13 (rotate by 13 places) is a simple letter substitution cipher t.pdfROT13 (rotate by 13 places) is a simple letter substitution cipher t.pdf
ROT13 (rotate by 13 places) is a simple letter substitution cipher t.pdf
 
question.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdfquestion.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdf
 
Question 25 A Multilateral agreement in which countries signed to ban.pdf
Question 25 A Multilateral agreement in which countries signed to ban.pdfQuestion 25 A Multilateral agreement in which countries signed to ban.pdf
Question 25 A Multilateral agreement in which countries signed to ban.pdf
 
Prove. Let n be a natural number. Any set of n integers {a1, a2, . ..pdf
Prove. Let n be a natural number. Any set of n integers {a1, a2, . ..pdfProve. Let n be a natural number. Any set of n integers {a1, a2, . ..pdf
Prove. Let n be a natural number. Any set of n integers {a1, a2, . ..pdf
 
1Write a Java program that calculates and displays the Fibonacciseri.pdf
1Write a Java program that calculates and displays the Fibonacciseri.pdf1Write a Java program that calculates and displays the Fibonacciseri.pdf
1Write a Java program that calculates and displays the Fibonacciseri.pdf
 
need an example of a System Anaysis and design project must have 3 .pdf
need an example of a System Anaysis and design project must have 3 .pdfneed an example of a System Anaysis and design project must have 3 .pdf
need an example of a System Anaysis and design project must have 3 .pdf
 
Money laundering has become a mechanism for terrorist financing acti.pdf
Money laundering has become a mechanism for terrorist financing acti.pdfMoney laundering has become a mechanism for terrorist financing acti.pdf
Money laundering has become a mechanism for terrorist financing acti.pdf
 
Let x be any set and let lambda SolutionProof. Obviously .pdf
Let x be any set and let lambda SolutionProof. Obviously .pdfLet x be any set and let lambda SolutionProof. Obviously .pdf
Let x be any set and let lambda SolutionProof. Obviously .pdf
 
Java public cts Node t next ni next SolutionYou hav.pdf
Java public cts Node t next ni next SolutionYou hav.pdfJava public cts Node t next ni next SolutionYou hav.pdf
Java public cts Node t next ni next SolutionYou hav.pdf
 

Recently uploaded

Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
Scopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsScopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsISCOPE Publication
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...Nguyen Thanh Tu Collection
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 

Recently uploaded (20)

Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Scopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsScopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS Publications
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 

Implement the findPre function of the LinkedList class .Node Lin.pdf

  • 1. Implement the findPre function of the LinkedList class . Node * LinkedList::findPre(int d) The job of this function is to return a pointer to the node the precedes a node with data equal to d. If d only occurs in the head node or d doesn't occur in any node, then the function should return a pointer to the last node in the list. If the list is empty then the function should return the null pointer. This is my current attemp, it is incorrect Node * LinkedList::findPre(int d){ Node * pre = headPtr; for (int i = 1; i < position-1; i++) pre = pre->next; // how pre points to the node right before the one we want to remove. Node *temp = pre->next; pre->next = temp->next; } Solution HI, Please find my implementation. Please let me know in case of any issue. Node * LinkedList::findPre(int d){ if(headPtr == NULL) return NULL; // if there is only one node(the first and last node is same), then return headPtr (last node) if(headPtr->next == NULL) return headPtr; Node *pre = headPtr; Node *current = headPtr->next; while(current != NULL){ if(current->data == d) return pre; pre = current; current = current->next; }
  • 2. return pre; // returning last node }