SlideShare a Scribd company logo
1 of 3
Linked List Copy Constructor Help!! Im having trouble doing this how would you do it since
mine doesnt want to work.
LinkedList::LinkedList(const LinkedList & alinked_list)
{
head = NULL;
Node* newNode;
Node* nodePtr;
Node* tempPtr;
if (!alinked_list.head)
return;
nodePtr = alinked_list.head;
head = new Node;
head->getData = nodePtr->getData;
head->getLink = NULL;
nodePtr = nodePtr->getLink;
tempPtr = head;
while (nodePtr != NULL)
{
newNode = new Node;
newNode->getData = nodePtr->getData;
newNode->getLink = NULL;
tempPtr->getLink = newNode;
tempPtr = newNode;
nodePtr = nodePtr->getLink;
}
I have 2 classes.
class LinkedList: public Node
{
private:
Node* head; }
class Node {
int data;
Node* link; }
if you want me to provide all of the code i have i can gladly do that.
Solution
//Corrected Program
LinkedList::LinkedList(const LinkedList & alinked_list)
{
head = NULL;
Node* newNode;
Node* nodePtr;
Node* tempPtr;
if (alinked_list.head==NULL)
return;
nodePtr = alinked_list.head;
head = new Node;
head->setData(nodePtr->getData());
head->setLink(NULL);
nodePtr = nodePtr->getLink();
tempPtr = head;
while (nodePtr != NULL)
{
newNode = new Node;
newNode->setData(nodePtr->getData());
newNode->setLink(NULL);
tempPtr->setLink(newNode);
tempPtr = newNode;
nodePtr = nodePtr->getLink();
}
class LinkedList: public Node
{
private:
Node* head;
public:
LinkedList(const LinkedList & alinked_list);
} ;
class Node {
int data;
Node* link;
public:
setData(int d)
{
data=d;
}
setLink(Node * p)
{
link=p;
}
getLink()
{
retrun link;
}
getData()
{
return data;
}
}
;

More Related Content

Similar to Linked List Copy Constructor Help!! Im having trouble doing this how w.docx

Using C++ use a linked list to create an alphabetical Conta.pdf
Using C++ use a linked list to create an alphabetical Conta.pdfUsing C++ use a linked list to create an alphabetical Conta.pdf
Using C++ use a linked list to create an alphabetical Conta.pdf
picscamshoppe
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
fortmdu
 
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
rohit219406
 
Add these methods to the code - -Create at least three classes such.pdf
Add these methods to the code -   -Create at least three classes such.pdfAdd these methods to the code -   -Create at least three classes such.pdf
Add these methods to the code - -Create at least three classes such.pdf
SebastianRzuHarrisw
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03
Nasir Mehmood
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
fathimahardwareelect
 
In the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdfIn the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdf
arjunstores123
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
vasavim9
 
c++ Computational Complexity filling in the following three .pdf
c++ Computational Complexity filling in the  following three .pdfc++ Computational Complexity filling in the  following three .pdf
c++ Computational Complexity filling in the following three .pdf
amitbagga0808
 
computer notes - Data Structures - 3
computer notes - Data Structures - 3computer notes - Data Structures - 3
computer notes - Data Structures - 3
ecomputernotes
 
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdfin C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
eyewaregallery
 

Similar to Linked List Copy Constructor Help!! Im having trouble doing this how w.docx (20)

Linkedlist
LinkedlistLinkedlist
Linkedlist
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdf
 
Using C++ use a linked list to create an alphabetical Conta.pdf
Using C++ use a linked list to create an alphabetical Conta.pdfUsing C++ use a linked list to create an alphabetical Conta.pdf
Using C++ use a linked list to create an alphabetical Conta.pdf
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.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
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docx
 
Add these methods to the code - -Create at least three classes such.pdf
Add these methods to the code -   -Create at least three classes such.pdfAdd these methods to the code -   -Create at least three classes such.pdf
Add these methods to the code - -Create at least three classes such.pdf
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
 
In the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdfIn the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdf
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
 
linkedlistwith animations.ppt
linkedlistwith animations.pptlinkedlistwith animations.ppt
linkedlistwith animations.ppt
 
c++ Computational Complexity filling in the following three .pdf
c++ Computational Complexity filling in the  following three .pdfc++ Computational Complexity filling in the  following three .pdf
c++ Computational Complexity filling in the following three .pdf
 
computer notes - Data Structures - 3
computer notes - Data Structures - 3computer notes - Data Structures - 3
computer notes - Data Structures - 3
 
Write a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdfWrite a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdf
 
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdfin C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
 
linked-list.ppt
linked-list.pptlinked-list.ppt
linked-list.ppt
 

More from hendriciraida

import java-io-IOException- import java-nio-file-Files- import java-ni.docx
import java-io-IOException- import java-nio-file-Files- import java-ni.docximport java-io-IOException- import java-nio-file-Files- import java-ni.docx
import java-io-IOException- import java-nio-file-Files- import java-ni.docx
hendriciraida
 

More from hendriciraida (20)

In a recent annual report and related Global Responsibiity Report- Sta.docx
In a recent annual report and related Global Responsibiity Report- Sta.docxIn a recent annual report and related Global Responsibiity Report- Sta.docx
In a recent annual report and related Global Responsibiity Report- Sta.docx
 
In a nutshell- Social Darwinism is employed by quasi-scientists and po.docx
In a nutshell- Social Darwinism is employed by quasi-scientists and po.docxIn a nutshell- Social Darwinism is employed by quasi-scientists and po.docx
In a nutshell- Social Darwinism is employed by quasi-scientists and po.docx
 
In a modern economy- who controls the creation of money- Who profits f.docx
In a modern economy- who controls the creation of money- Who profits f.docxIn a modern economy- who controls the creation of money- Who profits f.docx
In a modern economy- who controls the creation of money- Who profits f.docx
 
In a 1-1-5 page document (APA format- 12-point font- double-spaced) an.docx
In a 1-1-5 page document (APA format- 12-point font- double-spaced) an.docxIn a 1-1-5 page document (APA format- 12-point font- double-spaced) an.docx
In a 1-1-5 page document (APA format- 12-point font- double-spaced) an.docx
 
In 2017 in the economy of Cortania- Consumption was $1500-00- Investme.docx
In 2017 in the economy of Cortania- Consumption was $1500-00- Investme.docxIn 2017 in the economy of Cortania- Consumption was $1500-00- Investme.docx
In 2017 in the economy of Cortania- Consumption was $1500-00- Investme.docx
 
In 1868- the accidental introduction into the United States of the cot.docx
In 1868- the accidental introduction into the United States of the cot.docxIn 1868- the accidental introduction into the United States of the cot.docx
In 1868- the accidental introduction into the United States of the cot.docx
 
In 1950 the average year of education was 8 years- The standard deviat.docx
In 1950 the average year of education was 8 years- The standard deviat.docxIn 1950 the average year of education was 8 years- The standard deviat.docx
In 1950 the average year of education was 8 years- The standard deviat.docx
 
Important- Python Program- No imports- Use Custom Functions if necessa.docx
Important- Python Program- No imports- Use Custom Functions if necessa.docxImportant- Python Program- No imports- Use Custom Functions if necessa.docx
Important- Python Program- No imports- Use Custom Functions if necessa.docx
 
import java-io-IOException- import java-nio-file-Files- import java-ni.docx
import java-io-IOException- import java-nio-file-Files- import java-ni.docximport java-io-IOException- import java-nio-file-Files- import java-ni.docx
import java-io-IOException- import java-nio-file-Files- import java-ni.docx
 
Impact on Taxes- You have a marginal tax rate of 22-- You suddenly rea.docx
Impact on Taxes- You have a marginal tax rate of 22-- You suddenly rea.docxImpact on Taxes- You have a marginal tax rate of 22-- You suddenly rea.docx
Impact on Taxes- You have a marginal tax rate of 22-- You suddenly rea.docx
 
Immune complex is formed when antigen and antibody bind- Formation of.docx
Immune complex is formed when antigen and antibody bind- Formation of.docxImmune complex is formed when antigen and antibody bind- Formation of.docx
Immune complex is formed when antigen and antibody bind- Formation of.docx
 
Imani and Doug were divorced on December 31-2022 - after 10 years of m.docx
Imani and Doug were divorced on December 31-2022 - after 10 years of m.docxImani and Doug were divorced on December 31-2022 - after 10 years of m.docx
Imani and Doug were divorced on December 31-2022 - after 10 years of m.docx
 
Iloginning rav materiala invantoing siding favimaceriala inventory Dif.docx
Iloginning rav materiala invantoing siding favimaceriala inventory Dif.docxIloginning rav materiala invantoing siding favimaceriala inventory Dif.docx
Iloginning rav materiala invantoing siding favimaceriala inventory Dif.docx
 
ii) the 16000$ restumping fee iii- Ihe $2000 tor the new hot water sys.docx
ii) the 16000$ restumping fee iii- Ihe $2000 tor the new hot water sys.docxii) the 16000$ restumping fee iii- Ihe $2000 tor the new hot water sys.docx
ii) the 16000$ restumping fee iii- Ihe $2000 tor the new hot water sys.docx
 
If you were living in Galveston at the time- how could you have used y.docx
If you were living in Galveston at the time- how could you have used y.docxIf you were living in Galveston at the time- how could you have used y.docx
If you were living in Galveston at the time- how could you have used y.docx
 
If the share price of Nostos- a New York-based shipping firm- rises fr.docx
If the share price of Nostos- a New York-based shipping firm- rises fr.docxIf the share price of Nostos- a New York-based shipping firm- rises fr.docx
If the share price of Nostos- a New York-based shipping firm- rises fr.docx
 
If the mean annual return for common stocks is 11-0- and the standard.docx
If the mean annual return for common stocks is 11-0- and the standard.docxIf the mean annual return for common stocks is 11-0- and the standard.docx
If the mean annual return for common stocks is 11-0- and the standard.docx
 
If NADH donates a pair of electrons to the mitochondrial electron tran.docx
If NADH donates a pair of electrons to the mitochondrial electron tran.docxIf NADH donates a pair of electrons to the mitochondrial electron tran.docx
If NADH donates a pair of electrons to the mitochondrial electron tran.docx
 
If Molly's pension plan from Retirement Management Services included a.docx
If Molly's pension plan from Retirement Management Services included a.docxIf Molly's pension plan from Retirement Management Services included a.docx
If Molly's pension plan from Retirement Management Services included a.docx
 
If a varlable Y supersedes a variable X- then X must be influencing Y.docx
If a varlable Y supersedes a variable X- then X must be influencing Y.docxIf a varlable Y supersedes a variable X- then X must be influencing Y.docx
If a varlable Y supersedes a variable X- then X must be influencing Y.docx
 

Recently uploaded

SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MysoreMuleSoftMeetup
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Recently uploaded (20)

Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
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
 
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
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
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
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
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...
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
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...
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 

Linked List Copy Constructor Help!! Im having trouble doing this how w.docx

  • 1. Linked List Copy Constructor Help!! Im having trouble doing this how would you do it since mine doesnt want to work. LinkedList::LinkedList(const LinkedList & alinked_list) { head = NULL; Node* newNode; Node* nodePtr; Node* tempPtr; if (!alinked_list.head) return; nodePtr = alinked_list.head; head = new Node; head->getData = nodePtr->getData; head->getLink = NULL; nodePtr = nodePtr->getLink; tempPtr = head; while (nodePtr != NULL) { newNode = new Node; newNode->getData = nodePtr->getData; newNode->getLink = NULL; tempPtr->getLink = newNode; tempPtr = newNode; nodePtr = nodePtr->getLink; } I have 2 classes. class LinkedList: public Node { private: Node* head; } class Node { int data; Node* link; } if you want me to provide all of the code i have i can gladly do that.
  • 2. Solution //Corrected Program LinkedList::LinkedList(const LinkedList & alinked_list) { head = NULL; Node* newNode; Node* nodePtr; Node* tempPtr; if (alinked_list.head==NULL) return; nodePtr = alinked_list.head; head = new Node; head->setData(nodePtr->getData()); head->setLink(NULL); nodePtr = nodePtr->getLink(); tempPtr = head; while (nodePtr != NULL) { newNode = new Node; newNode->setData(nodePtr->getData()); newNode->setLink(NULL); tempPtr->setLink(newNode); tempPtr = newNode; nodePtr = nodePtr->getLink(); } class LinkedList: public Node { private: Node* head; public: LinkedList(const LinkedList & alinked_list); } ;
  • 3. class Node { int data; Node* link; public: setData(int d) { data=d; } setLink(Node * p) { link=p; } getLink() { retrun link; } getData() { return data; } } ;