SlideShare a Scribd company logo
1 of 1
Download to read offline
Implement the insertFirst member function of the LinkedList class . Your header will be
void LinkedList::insertFirst(int d)
The job of insertFirst is to create a new Node with data equal to d and insert the Node at the front
of the list. Don't forget to update headPtr and length. Also make sure you handle the case where
the list is initially empty.
My incorrect attempt:
void LinkedList::insertFirst(int d){
int length;
Node * nodeToInsert = new Node(value, headPtr);
headPtr = nodeToInsert;
length++;
Solution
Since nothing is given, I am assuming the node structure as:
struct Node{
int data;
Node *next;
}
void LinkedList::insertFirst(int d){
Node *nodeToInsert = (Node *)malloc(sizeof(Node *));
nodeToInsert->data = d;
nodeToInsert->next = NULL;
if(headPtr != NULL){
nodeToInsert->next = headPtr;
}
headPtr = nodeToInsert;
length++;
}

More Related Content

Similar to Implement the insertFirst member function of the LinkedList class . .pdf

Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfformicreation
 
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
 
Using the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfUsing the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfconnellalykshamesb60
 
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
 
ItemNodeh include ltiostreamgt include ltstring.pdf
ItemNodeh    include ltiostreamgt include ltstring.pdfItemNodeh    include ltiostreamgt include ltstring.pdf
ItemNodeh include ltiostreamgt include ltstring.pdfacmefit
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhvasavim9
 
Chap 2 Arrays and Structures.ppt
Chap 2  Arrays and Structures.pptChap 2  Arrays and Structures.ppt
Chap 2 Arrays and Structures.pptshashankbhadouria4
 
Chap 2 Arrays and Structures.pptx
Chap 2  Arrays and Structures.pptxChap 2  Arrays and Structures.pptx
Chap 2 Arrays and Structures.pptxshashankbhadouria4
 
In this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdfIn this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdffantasiatheoutofthef
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queuessuser7319f8
 
To complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdfTo complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdfezycolours78
 
linkedlistwith animations.ppt
linkedlistwith animations.pptlinkedlistwith animations.ppt
linkedlistwith animations.pptMuhammadShafi89
 
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
 
C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdfdeepua8
 

Similar to Implement the insertFirst member function of the LinkedList class . .pdf (20)

17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 
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
 
Using the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfUsing the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdf
 
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
Linked listLinked list
Linked list
 
ItemNodeh include ltiostreamgt include ltstring.pdf
ItemNodeh    include ltiostreamgt include ltstring.pdfItemNodeh    include ltiostreamgt include ltstring.pdf
ItemNodeh include ltiostreamgt include ltstring.pdf
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
 
Chap 2 Arrays and Structures.ppt
Chap 2  Arrays and Structures.pptChap 2  Arrays and Structures.ppt
Chap 2 Arrays and Structures.ppt
 
Chap 2 Arrays and Structures.pptx
Chap 2  Arrays and Structures.pptxChap 2  Arrays and Structures.pptx
Chap 2 Arrays and Structures.pptx
 
In this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdfIn this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdf
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
 
To complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdfTo complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdf
 
linkedlistwith animations.ppt
linkedlistwith animations.pptlinkedlistwith animations.ppt
linkedlistwith animations.ppt
 
Linked list
Linked list Linked list
Linked list
 
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
 
Adt of lists
Adt of listsAdt of lists
Adt of lists
 
C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdf
 

More from infomalad

Operating systems have to balance the conflicting goals of convenien.pdf
Operating systems have to balance the conflicting goals of convenien.pdfOperating systems have to balance the conflicting goals of convenien.pdf
Operating systems have to balance the conflicting goals of convenien.pdfinfomalad
 
PARTI PHILOSOPHY AND CONCEPTS FLEXIBLE BENEFITS SYSTEM IMPLEMENTATION.pdf
PARTI PHILOSOPHY AND CONCEPTS FLEXIBLE BENEFITS SYSTEM IMPLEMENTATION.pdfPARTI PHILOSOPHY AND CONCEPTS FLEXIBLE BENEFITS SYSTEM IMPLEMENTATION.pdf
PARTI PHILOSOPHY AND CONCEPTS FLEXIBLE BENEFITS SYSTEM IMPLEMENTATION.pdfinfomalad
 
On SQL Managment studioThis lab is all about database normalizatio.pdf
On SQL Managment studioThis lab is all about database normalizatio.pdfOn SQL Managment studioThis lab is all about database normalizatio.pdf
On SQL Managment studioThis lab is all about database normalizatio.pdfinfomalad
 
Maria, an experienced shipping clerk, can fill a certain order in 11.pdf
Maria, an experienced shipping clerk, can fill a certain order in 11.pdfMaria, an experienced shipping clerk, can fill a certain order in 11.pdf
Maria, an experienced shipping clerk, can fill a certain order in 11.pdfinfomalad
 
List the problems that can be efficiently solved by Evolutionary P.pdf
List the problems that can be efficiently solved by Evolutionary P.pdfList the problems that can be efficiently solved by Evolutionary P.pdf
List the problems that can be efficiently solved by Evolutionary P.pdfinfomalad
 
I need to get a 910 in order to pass this and I have 40 mins from n.pdf
I need to get a 910 in order to pass this and I have 40 mins from n.pdfI need to get a 910 in order to pass this and I have 40 mins from n.pdf
I need to get a 910 in order to pass this and I have 40 mins from n.pdfinfomalad
 
If related parties complete a qualified like-kind exchange, how long.pdf
If related parties complete a qualified like-kind exchange, how long.pdfIf related parties complete a qualified like-kind exchange, how long.pdf
If related parties complete a qualified like-kind exchange, how long.pdfinfomalad
 
How innovative offerings gain acceptance within market segmentsH.pdf
How innovative offerings gain acceptance within market segmentsH.pdfHow innovative offerings gain acceptance within market segmentsH.pdf
How innovative offerings gain acceptance within market segmentsH.pdfinfomalad
 
How does an organization socialize an individualHow ATM(automated.pdf
How does an organization socialize an individualHow ATM(automated.pdfHow does an organization socialize an individualHow ATM(automated.pdf
How does an organization socialize an individualHow ATM(automated.pdfinfomalad
 
Homework Develop a strategylies) to get a house. Consider possible h.pdf
Homework Develop a strategylies) to get a house. Consider possible h.pdfHomework Develop a strategylies) to get a house. Consider possible h.pdf
Homework Develop a strategylies) to get a house. Consider possible h.pdfinfomalad
 
Given a definition of a group Given a definition of a group.pdf
Given a definition of a group Given a definition of a group.pdfGiven a definition of a group Given a definition of a group.pdf
Given a definition of a group Given a definition of a group.pdfinfomalad
 
Given the indexed collection of denumerable sets A_i with i N, prov.pdf
Given the indexed collection of denumerable sets A_i with i  N,  prov.pdfGiven the indexed collection of denumerable sets A_i with i  N,  prov.pdf
Given the indexed collection of denumerable sets A_i with i N, prov.pdfinfomalad
 
give an example of a successful progect thats ben done by a virtual .pdf
give an example of a successful progect thats ben done by a virtual .pdfgive an example of a successful progect thats ben done by a virtual .pdf
give an example of a successful progect thats ben done by a virtual .pdfinfomalad
 
File name a2.cppTaskFor this assignment, you are required to ei.pdf
File name a2.cppTaskFor this assignment, you are required to ei.pdfFile name a2.cppTaskFor this assignment, you are required to ei.pdf
File name a2.cppTaskFor this assignment, you are required to ei.pdfinfomalad
 
Explain in detail the DTE-DCE TransmissionSolutionData commun.pdf
Explain in detail the DTE-DCE TransmissionSolutionData commun.pdfExplain in detail the DTE-DCE TransmissionSolutionData commun.pdf
Explain in detail the DTE-DCE TransmissionSolutionData commun.pdfinfomalad
 
Find an example of a real project with a real project manager. The pr.pdf
Find an example of a real project with a real project manager. The pr.pdfFind an example of a real project with a real project manager. The pr.pdf
Find an example of a real project with a real project manager. The pr.pdfinfomalad
 
Discuss the importance of security and what elements need to be addr.pdf
Discuss the importance of security and what elements need to be addr.pdfDiscuss the importance of security and what elements need to be addr.pdf
Discuss the importance of security and what elements need to be addr.pdfinfomalad
 
Define financial engineering in terms of how to change the risk-retu.pdf
Define financial engineering in terms of how to change the risk-retu.pdfDefine financial engineering in terms of how to change the risk-retu.pdf
Define financial engineering in terms of how to change the risk-retu.pdfinfomalad
 
As a result of total quality management, organizational changes in t.pdf
As a result of total quality management, organizational changes in t.pdfAs a result of total quality management, organizational changes in t.pdf
As a result of total quality management, organizational changes in t.pdfinfomalad
 
Complete and balance the following redox equation. Show all work and.pdf
Complete and balance the following redox equation. Show all work and.pdfComplete and balance the following redox equation. Show all work and.pdf
Complete and balance the following redox equation. Show all work and.pdfinfomalad
 

More from infomalad (20)

Operating systems have to balance the conflicting goals of convenien.pdf
Operating systems have to balance the conflicting goals of convenien.pdfOperating systems have to balance the conflicting goals of convenien.pdf
Operating systems have to balance the conflicting goals of convenien.pdf
 
PARTI PHILOSOPHY AND CONCEPTS FLEXIBLE BENEFITS SYSTEM IMPLEMENTATION.pdf
PARTI PHILOSOPHY AND CONCEPTS FLEXIBLE BENEFITS SYSTEM IMPLEMENTATION.pdfPARTI PHILOSOPHY AND CONCEPTS FLEXIBLE BENEFITS SYSTEM IMPLEMENTATION.pdf
PARTI PHILOSOPHY AND CONCEPTS FLEXIBLE BENEFITS SYSTEM IMPLEMENTATION.pdf
 
On SQL Managment studioThis lab is all about database normalizatio.pdf
On SQL Managment studioThis lab is all about database normalizatio.pdfOn SQL Managment studioThis lab is all about database normalizatio.pdf
On SQL Managment studioThis lab is all about database normalizatio.pdf
 
Maria, an experienced shipping clerk, can fill a certain order in 11.pdf
Maria, an experienced shipping clerk, can fill a certain order in 11.pdfMaria, an experienced shipping clerk, can fill a certain order in 11.pdf
Maria, an experienced shipping clerk, can fill a certain order in 11.pdf
 
List the problems that can be efficiently solved by Evolutionary P.pdf
List the problems that can be efficiently solved by Evolutionary P.pdfList the problems that can be efficiently solved by Evolutionary P.pdf
List the problems that can be efficiently solved by Evolutionary P.pdf
 
I need to get a 910 in order to pass this and I have 40 mins from n.pdf
I need to get a 910 in order to pass this and I have 40 mins from n.pdfI need to get a 910 in order to pass this and I have 40 mins from n.pdf
I need to get a 910 in order to pass this and I have 40 mins from n.pdf
 
If related parties complete a qualified like-kind exchange, how long.pdf
If related parties complete a qualified like-kind exchange, how long.pdfIf related parties complete a qualified like-kind exchange, how long.pdf
If related parties complete a qualified like-kind exchange, how long.pdf
 
How innovative offerings gain acceptance within market segmentsH.pdf
How innovative offerings gain acceptance within market segmentsH.pdfHow innovative offerings gain acceptance within market segmentsH.pdf
How innovative offerings gain acceptance within market segmentsH.pdf
 
How does an organization socialize an individualHow ATM(automated.pdf
How does an organization socialize an individualHow ATM(automated.pdfHow does an organization socialize an individualHow ATM(automated.pdf
How does an organization socialize an individualHow ATM(automated.pdf
 
Homework Develop a strategylies) to get a house. Consider possible h.pdf
Homework Develop a strategylies) to get a house. Consider possible h.pdfHomework Develop a strategylies) to get a house. Consider possible h.pdf
Homework Develop a strategylies) to get a house. Consider possible h.pdf
 
Given a definition of a group Given a definition of a group.pdf
Given a definition of a group Given a definition of a group.pdfGiven a definition of a group Given a definition of a group.pdf
Given a definition of a group Given a definition of a group.pdf
 
Given the indexed collection of denumerable sets A_i with i N, prov.pdf
Given the indexed collection of denumerable sets A_i with i  N,  prov.pdfGiven the indexed collection of denumerable sets A_i with i  N,  prov.pdf
Given the indexed collection of denumerable sets A_i with i N, prov.pdf
 
give an example of a successful progect thats ben done by a virtual .pdf
give an example of a successful progect thats ben done by a virtual .pdfgive an example of a successful progect thats ben done by a virtual .pdf
give an example of a successful progect thats ben done by a virtual .pdf
 
File name a2.cppTaskFor this assignment, you are required to ei.pdf
File name a2.cppTaskFor this assignment, you are required to ei.pdfFile name a2.cppTaskFor this assignment, you are required to ei.pdf
File name a2.cppTaskFor this assignment, you are required to ei.pdf
 
Explain in detail the DTE-DCE TransmissionSolutionData commun.pdf
Explain in detail the DTE-DCE TransmissionSolutionData commun.pdfExplain in detail the DTE-DCE TransmissionSolutionData commun.pdf
Explain in detail the DTE-DCE TransmissionSolutionData commun.pdf
 
Find an example of a real project with a real project manager. The pr.pdf
Find an example of a real project with a real project manager. The pr.pdfFind an example of a real project with a real project manager. The pr.pdf
Find an example of a real project with a real project manager. The pr.pdf
 
Discuss the importance of security and what elements need to be addr.pdf
Discuss the importance of security and what elements need to be addr.pdfDiscuss the importance of security and what elements need to be addr.pdf
Discuss the importance of security and what elements need to be addr.pdf
 
Define financial engineering in terms of how to change the risk-retu.pdf
Define financial engineering in terms of how to change the risk-retu.pdfDefine financial engineering in terms of how to change the risk-retu.pdf
Define financial engineering in terms of how to change the risk-retu.pdf
 
As a result of total quality management, organizational changes in t.pdf
As a result of total quality management, organizational changes in t.pdfAs a result of total quality management, organizational changes in t.pdf
As a result of total quality management, organizational changes in t.pdf
 
Complete and balance the following redox equation. Show all work and.pdf
Complete and balance the following redox equation. Show all work and.pdfComplete and balance the following redox equation. Show all work and.pdf
Complete and balance the following redox equation. Show all work and.pdf
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answersdalebeck957
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 

Recently uploaded (20)

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 

Implement the insertFirst member function of the LinkedList class . .pdf

  • 1. Implement the insertFirst member function of the LinkedList class . Your header will be void LinkedList::insertFirst(int d) The job of insertFirst is to create a new Node with data equal to d and insert the Node at the front of the list. Don't forget to update headPtr and length. Also make sure you handle the case where the list is initially empty. My incorrect attempt: void LinkedList::insertFirst(int d){ int length; Node * nodeToInsert = new Node(value, headPtr); headPtr = nodeToInsert; length++; Solution Since nothing is given, I am assuming the node structure as: struct Node{ int data; Node *next; } void LinkedList::insertFirst(int d){ Node *nodeToInsert = (Node *)malloc(sizeof(Node *)); nodeToInsert->data = d; nodeToInsert->next = NULL; if(headPtr != NULL){ nodeToInsert->next = headPtr; } headPtr = nodeToInsert; length++; }