SlideShare a Scribd company logo
could you implement this function please, im having issues with it.
void makeList (const ListNode::value_type [],const size_t& count)
class ListNode
{
public:
typedef int value_type;
ListNode (value_type d = value_type(), ListNode* n = NULL) { datum = d; next = n; }
//Assessor
value_type getDatum () const { return datum; }
ListNode const* getNext () const { return next; }
//Mutator
void setDatum (const value_type& d) {datum = d; }
ListNode* getNext () { return next; }
void setNext (ListNode* new_link) {next = new_link; }
private:
value_type datum;
ListNode* next;
};
class LinkedList
{
public:
LinkedList ();
virtual ~LinkedList ();
void insertItem (ListNode::value_type);
void makeList (const ListNode::value_type [],const size_t& count);
void deleteList ();
//The following friend function is implemented in lablinklist.cpp
friend std::ostream& operator<<(std::ostream&, const LinkedList&);
private:
ListNode* head;
};
This is the pseudocode, but i still have a hard time undertanding it.
Creating a List (makeList(const ListNode::value_type [],const size_t& count)) This function
receives an array in the order that we want to add it to the linkedlist. Index 0 will be the head
node, index n will be the last node.
First, create a node initialized with a data value and a NULL pointer. Set the "head" to point to
the first node. Set up a current-pointer to the first node (or "head"). Get a data value for the next
node. While more nodes to add { Create a new node initialized with the data value and a NULL
pointer. Set the current-pointer link member ("next") to the new node. Set the current-pointer to
point to the new node. Get a data value for the next node. }
Thanks.
Solution
//linkedList.h
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include
#include
class ListNode
{
public:
typedef int value_type;
ListNode(value_type d = value_type(), ListNode* n = NULL) { datum = d; next = n; }
//Assessor
value_type getDatum() const { return datum; }
ListNode const* getNext() const { return next; }
//Mutator
void setDatum(const value_type& d) { datum = d; }
ListNode* getNext() { return next; }
void setNext(ListNode* new_link) { next = new_link; }
private:
value_type datum;
ListNode* next;
};
class LinkedList
{
public:
LinkedList();
virtual ~LinkedList();
void insertItem(ListNode::value_type);
void makeList(const ListNode::value_type[], const size_t& count);
void deleteList();
//The following friend function is implemented in lablinklist.cpp
friend std::ostream& operator<<(std::ostream&, const LinkedList&);
private:
ListNode* head;
};
#endif
-------------------------------------------------------------
//linkedList.cpp
#include "linkedlist.h"
LinkedList::LinkedList()
{
head = NULL;
}
LinkedList::~LinkedList()
{
ListNode *tmp = head;
while (tmp != NULL)
{
head = head->getNext();
delete tmp;
tmp = head;
}
}
void LinkedList::insertItem(ListNode::value_type item)
{
ListNode *newNode,*cur = head;
newNode = new ListNode;
newNode->setDatum(item);
newNode->setNext(NULL);
if (head == NULL)
{
head = newNode;
}
else
{
while (cur->getNext() != NULL)
{
cur = cur->getNext();
}
cur->setNext(newNode);
}
}
void LinkedList::makeList(const ListNode::value_type num[], const size_t& count)
{
int i = 0;
while ( i < count)
{
insertItem(num[i++]);
}
}
void LinkedList::deleteList()
{
ListNode *tmp = head;
while (tmp != NULL)
{
head = head->getNext();
delete tmp;
tmp = head;
}
}
std::ostream& operator<<(std::ostream& os, const LinkedList &srcList) {
//Set a current-pointer to the "head".
ListNode* cursor = srcList.head;
//While current-pointer is not NULL
while (cursor != NULL)
{
//Print the data member ("datum") of the current node
os << "->[" << cursor->getDatum() << "]";
//Set the current-pointer to the "next" node in the list.
cursor = cursor->getNext();
}
//Print out a basic termination symbol
std::cout << "--X" << std::endl;
return os;
}
---------------------------------------
//main.cpp
#include
#include "linkedlist.h"
using namespace std;
int main() {
LinkedList list1;
//Test of adding items out of order
list1.insertItem(5);
list1.insertItem(20);
list1.insertItem(10);
cout << "After adding 5,20,10 to list ,List contains" << endl;
cout << list1 << endl;
//Test of deleting entire list
list1.deleteList();
cout << "After deleteing list,List contains" << endl;
cout << list1 << endl;
//Add items again in same order as before
cout << "After adding 5,20,10 to list ,List contains" << endl;
list1.insertItem(5);
list1.insertItem(20);
list1.insertItem(10);
cout << list1 << endl;
//Now replace list with a new one in a specific order
int pow2[] = { 1, 2, 4, 8, 16, 32, 16, 8, 4, 2, 1 };
list1.makeList(pow2, sizeof(pow2) / sizeof(int));
cout << "After calling makeList function" << endl;
cout << list1 << endl;
//Returning a non-zero number, if not 3, then we know it seg-faulted
return 3;
}
-----------------------------------------------------------------------------------------------------------
After adding 5,20,10 to list ,List contains
->[5]->[20]->[10]--X
After deleteing list,List contains
--X
After adding 5,20,10 to list ,List contains
->[5]->[20]->[10]--X
After calling makeList function
->[5]->[20]->[10]->[1]->[2]->[4]->[8]->[16]->[32]->[16]->[8]->[4]->[2]->[1]--X

More Related Content

Similar to could you implement this function please, im having issues with it..pdf

C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
poblettesedanoree498
 
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptxData Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
RashidFaridChishti
 
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
 
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
BrianGHiNewmanv
 
For this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docxFor this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docx
mckellarhastings
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
vishalateen
 
How do you update an address according to this code- Currently- I fig.pdf
How do you update an address according to this code-  Currently- I fig.pdfHow do you update an address according to this code-  Currently- I fig.pdf
How do you update an address according to this code- Currently- I fig.pdf
ThomasXUMParsonsx
 
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfA)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
anton291
 
#include iostream #include cstddefusing namespace std;temp.pdf
#include iostream #include cstddefusing namespace std;temp.pdf#include iostream #include cstddefusing namespace std;temp.pdf
#include iostream #include cstddefusing namespace std;temp.pdf
karan8801
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdf
Ankitchhabra28
 
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
deepua8
 
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 03Nasir 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
 
Below is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxBelow is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docx
gilliandunce53776
 
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfCreate a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
hadpadrrajeshh
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
KylaMaeGarcia1
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
vasavim9
 
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
 
write recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.pdfwrite recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.pdf
arpitcomputronics
 
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
 

Similar to could you implement this function please, im having issues with it..pdf (20)

C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
 
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptxData Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
 
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
 
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
 
For this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docxFor this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docx
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
 
How do you update an address according to this code- Currently- I fig.pdf
How do you update an address according to this code-  Currently- I fig.pdfHow do you update an address according to this code-  Currently- I fig.pdf
How do you update an address according to this code- Currently- I fig.pdf
 
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfA)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
 
#include iostream #include cstddefusing namespace std;temp.pdf
#include iostream #include cstddefusing namespace std;temp.pdf#include iostream #include cstddefusing namespace std;temp.pdf
#include iostream #include cstddefusing namespace std;temp.pdf
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.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
C code on linked list #include stdio.h #include stdlib.h.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
 
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
 
Below is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxBelow is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docx
 
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfCreate a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
 
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
 
write recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.pdfwrite recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.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
 

More from feroz544

Case studyInitial history27-year-old female comlaining of sympto.pdf
Case studyInitial history27-year-old female comlaining of sympto.pdfCase studyInitial history27-year-old female comlaining of sympto.pdf
Case studyInitial history27-year-old female comlaining of sympto.pdf
feroz544
 
I appreciate any help with the following questions.(1)    What typ.pdf
I appreciate any help with the following questions.(1)    What typ.pdfI appreciate any help with the following questions.(1)    What typ.pdf
I appreciate any help with the following questions.(1)    What typ.pdf
feroz544
 
How do the IPv6 autoconfiguration and numbering features work What .pdf
How do the IPv6 autoconfiguration and numbering features work What .pdfHow do the IPv6 autoconfiguration and numbering features work What .pdf
How do the IPv6 autoconfiguration and numbering features work What .pdf
feroz544
 
Government Audits & Fraud Reporting For discussion During an audit .pdf
Government Audits & Fraud Reporting For discussion During an audit .pdfGovernment Audits & Fraud Reporting For discussion During an audit .pdf
Government Audits & Fraud Reporting For discussion During an audit .pdf
feroz544
 
Given L1 and Prove a llb are supplementary. 3 2 Proof It is given .pdf
Given L1 and Prove a llb are supplementary. 3 2 Proof It is given .pdfGiven L1 and Prove a llb are supplementary. 3 2 Proof It is given .pdf
Given L1 and Prove a llb are supplementary. 3 2 Proof It is given .pdf
feroz544
 
Explain viewing the nonprofit organization as an economic entity and.pdf
Explain viewing the nonprofit organization as an economic entity and.pdfExplain viewing the nonprofit organization as an economic entity and.pdf
Explain viewing the nonprofit organization as an economic entity and.pdf
feroz544
 
Explain the concept and cause of freezing point depression. Elaborat.pdf
Explain the concept and cause of freezing point depression. Elaborat.pdfExplain the concept and cause of freezing point depression. Elaborat.pdf
Explain the concept and cause of freezing point depression. Elaborat.pdf
feroz544
 
Company management has asked that you compare the OSSTMM and the PTE.pdf
Company management has asked that you compare the OSSTMM and the PTE.pdfCompany management has asked that you compare the OSSTMM and the PTE.pdf
Company management has asked that you compare the OSSTMM and the PTE.pdf
feroz544
 
As people engage in more international travel and become more famili.pdf
As people engage in more international travel and become more famili.pdfAs people engage in more international travel and become more famili.pdf
As people engage in more international travel and become more famili.pdf
feroz544
 
Consider a l-D elastic bar problem defined on [0, 4]. The domain .pdf
Consider a l-D elastic bar problem defined on [0, 4]. The domain .pdfConsider a l-D elastic bar problem defined on [0, 4]. The domain .pdf
Consider a l-D elastic bar problem defined on [0, 4]. The domain .pdf
feroz544
 
Click to add title 2. Explain the nature of the social structurecast.pdf
Click to add title 2. Explain the nature of the social structurecast.pdfClick to add title 2. Explain the nature of the social structurecast.pdf
Click to add title 2. Explain the nature of the social structurecast.pdf
feroz544
 
Based on the following data, what is the working capital Accounts p.pdf
Based on the following data, what is the working capital Accounts p.pdfBased on the following data, what is the working capital Accounts p.pdf
Based on the following data, what is the working capital Accounts p.pdf
feroz544
 
who are the people that steal cashSolutionPeople that steal c.pdf
who are the people that steal cashSolutionPeople that steal c.pdfwho are the people that steal cashSolutionPeople that steal c.pdf
who are the people that steal cashSolutionPeople that steal c.pdf
feroz544
 
Why is nucleotide synthesis an important pathway for medical interve.pdf
Why is nucleotide synthesis an important pathway for medical interve.pdfWhy is nucleotide synthesis an important pathway for medical interve.pdf
Why is nucleotide synthesis an important pathway for medical interve.pdf
feroz544
 
Why do some argue that the Fed made the Great Depression worse S.pdf
Why do some argue that the Fed made the Great Depression worse S.pdfWhy do some argue that the Fed made the Great Depression worse S.pdf
Why do some argue that the Fed made the Great Depression worse S.pdf
feroz544
 
Which of the following is a characteristic of TQMI. A focus on th.pdf
Which of the following is a characteristic of TQMI. A focus on th.pdfWhich of the following is a characteristic of TQMI. A focus on th.pdf
Which of the following is a characteristic of TQMI. A focus on th.pdf
feroz544
 
Which of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdfWhich of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdf
feroz544
 
A 0.28 mol sample of a weak acid with an unknown pKa was combined wi.pdf
A 0.28 mol sample of a weak acid with an unknown pKa was combined wi.pdfA 0.28 mol sample of a weak acid with an unknown pKa was combined wi.pdf
A 0.28 mol sample of a weak acid with an unknown pKa was combined wi.pdf
feroz544
 
What was the first primate to have Y-5 molar pattern GibbonsSol.pdf
What was the first primate to have Y-5 molar pattern  GibbonsSol.pdfWhat was the first primate to have Y-5 molar pattern  GibbonsSol.pdf
What was the first primate to have Y-5 molar pattern GibbonsSol.pdf
feroz544
 
What special problems does ECB confront A. The ECB must function w.pdf
What special problems does ECB confront A. The ECB must function w.pdfWhat special problems does ECB confront A. The ECB must function w.pdf
What special problems does ECB confront A. The ECB must function w.pdf
feroz544
 

More from feroz544 (20)

Case studyInitial history27-year-old female comlaining of sympto.pdf
Case studyInitial history27-year-old female comlaining of sympto.pdfCase studyInitial history27-year-old female comlaining of sympto.pdf
Case studyInitial history27-year-old female comlaining of sympto.pdf
 
I appreciate any help with the following questions.(1)    What typ.pdf
I appreciate any help with the following questions.(1)    What typ.pdfI appreciate any help with the following questions.(1)    What typ.pdf
I appreciate any help with the following questions.(1)    What typ.pdf
 
How do the IPv6 autoconfiguration and numbering features work What .pdf
How do the IPv6 autoconfiguration and numbering features work What .pdfHow do the IPv6 autoconfiguration and numbering features work What .pdf
How do the IPv6 autoconfiguration and numbering features work What .pdf
 
Government Audits & Fraud Reporting For discussion During an audit .pdf
Government Audits & Fraud Reporting For discussion During an audit .pdfGovernment Audits & Fraud Reporting For discussion During an audit .pdf
Government Audits & Fraud Reporting For discussion During an audit .pdf
 
Given L1 and Prove a llb are supplementary. 3 2 Proof It is given .pdf
Given L1 and Prove a llb are supplementary. 3 2 Proof It is given .pdfGiven L1 and Prove a llb are supplementary. 3 2 Proof It is given .pdf
Given L1 and Prove a llb are supplementary. 3 2 Proof It is given .pdf
 
Explain viewing the nonprofit organization as an economic entity and.pdf
Explain viewing the nonprofit organization as an economic entity and.pdfExplain viewing the nonprofit organization as an economic entity and.pdf
Explain viewing the nonprofit organization as an economic entity and.pdf
 
Explain the concept and cause of freezing point depression. Elaborat.pdf
Explain the concept and cause of freezing point depression. Elaborat.pdfExplain the concept and cause of freezing point depression. Elaborat.pdf
Explain the concept and cause of freezing point depression. Elaborat.pdf
 
Company management has asked that you compare the OSSTMM and the PTE.pdf
Company management has asked that you compare the OSSTMM and the PTE.pdfCompany management has asked that you compare the OSSTMM and the PTE.pdf
Company management has asked that you compare the OSSTMM and the PTE.pdf
 
As people engage in more international travel and become more famili.pdf
As people engage in more international travel and become more famili.pdfAs people engage in more international travel and become more famili.pdf
As people engage in more international travel and become more famili.pdf
 
Consider a l-D elastic bar problem defined on [0, 4]. The domain .pdf
Consider a l-D elastic bar problem defined on [0, 4]. The domain .pdfConsider a l-D elastic bar problem defined on [0, 4]. The domain .pdf
Consider a l-D elastic bar problem defined on [0, 4]. The domain .pdf
 
Click to add title 2. Explain the nature of the social structurecast.pdf
Click to add title 2. Explain the nature of the social structurecast.pdfClick to add title 2. Explain the nature of the social structurecast.pdf
Click to add title 2. Explain the nature of the social structurecast.pdf
 
Based on the following data, what is the working capital Accounts p.pdf
Based on the following data, what is the working capital Accounts p.pdfBased on the following data, what is the working capital Accounts p.pdf
Based on the following data, what is the working capital Accounts p.pdf
 
who are the people that steal cashSolutionPeople that steal c.pdf
who are the people that steal cashSolutionPeople that steal c.pdfwho are the people that steal cashSolutionPeople that steal c.pdf
who are the people that steal cashSolutionPeople that steal c.pdf
 
Why is nucleotide synthesis an important pathway for medical interve.pdf
Why is nucleotide synthesis an important pathway for medical interve.pdfWhy is nucleotide synthesis an important pathway for medical interve.pdf
Why is nucleotide synthesis an important pathway for medical interve.pdf
 
Why do some argue that the Fed made the Great Depression worse S.pdf
Why do some argue that the Fed made the Great Depression worse S.pdfWhy do some argue that the Fed made the Great Depression worse S.pdf
Why do some argue that the Fed made the Great Depression worse S.pdf
 
Which of the following is a characteristic of TQMI. A focus on th.pdf
Which of the following is a characteristic of TQMI. A focus on th.pdfWhich of the following is a characteristic of TQMI. A focus on th.pdf
Which of the following is a characteristic of TQMI. A focus on th.pdf
 
Which of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdfWhich of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdf
 
A 0.28 mol sample of a weak acid with an unknown pKa was combined wi.pdf
A 0.28 mol sample of a weak acid with an unknown pKa was combined wi.pdfA 0.28 mol sample of a weak acid with an unknown pKa was combined wi.pdf
A 0.28 mol sample of a weak acid with an unknown pKa was combined wi.pdf
 
What was the first primate to have Y-5 molar pattern GibbonsSol.pdf
What was the first primate to have Y-5 molar pattern  GibbonsSol.pdfWhat was the first primate to have Y-5 molar pattern  GibbonsSol.pdf
What was the first primate to have Y-5 molar pattern GibbonsSol.pdf
 
What special problems does ECB confront A. The ECB must function w.pdf
What special problems does ECB confront A. The ECB must function w.pdfWhat special problems does ECB confront A. The ECB must function w.pdf
What special problems does ECB confront A. The ECB must function w.pdf
 

Recently uploaded

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 

Recently uploaded (20)

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 

could you implement this function please, im having issues with it..pdf

  • 1. could you implement this function please, im having issues with it. void makeList (const ListNode::value_type [],const size_t& count) class ListNode { public: typedef int value_type; ListNode (value_type d = value_type(), ListNode* n = NULL) { datum = d; next = n; } //Assessor value_type getDatum () const { return datum; } ListNode const* getNext () const { return next; } //Mutator void setDatum (const value_type& d) {datum = d; } ListNode* getNext () { return next; } void setNext (ListNode* new_link) {next = new_link; } private: value_type datum; ListNode* next; }; class LinkedList { public: LinkedList (); virtual ~LinkedList (); void insertItem (ListNode::value_type); void makeList (const ListNode::value_type [],const size_t& count); void deleteList (); //The following friend function is implemented in lablinklist.cpp friend std::ostream& operator<<(std::ostream&, const LinkedList&);
  • 2. private: ListNode* head; }; This is the pseudocode, but i still have a hard time undertanding it. Creating a List (makeList(const ListNode::value_type [],const size_t& count)) This function receives an array in the order that we want to add it to the linkedlist. Index 0 will be the head node, index n will be the last node. First, create a node initialized with a data value and a NULL pointer. Set the "head" to point to the first node. Set up a current-pointer to the first node (or "head"). Get a data value for the next node. While more nodes to add { Create a new node initialized with the data value and a NULL pointer. Set the current-pointer link member ("next") to the new node. Set the current-pointer to point to the new node. Get a data value for the next node. } Thanks. Solution //linkedList.h #ifndef LINKEDLIST_H #define LINKEDLIST_H #include #include class ListNode { public: typedef int value_type; ListNode(value_type d = value_type(), ListNode* n = NULL) { datum = d; next = n; } //Assessor value_type getDatum() const { return datum; } ListNode const* getNext() const { return next; } //Mutator void setDatum(const value_type& d) { datum = d; } ListNode* getNext() { return next; } void setNext(ListNode* new_link) { next = new_link; } private: value_type datum; ListNode* next;
  • 3. }; class LinkedList { public: LinkedList(); virtual ~LinkedList(); void insertItem(ListNode::value_type); void makeList(const ListNode::value_type[], const size_t& count); void deleteList(); //The following friend function is implemented in lablinklist.cpp friend std::ostream& operator<<(std::ostream&, const LinkedList&); private: ListNode* head; }; #endif ------------------------------------------------------------- //linkedList.cpp #include "linkedlist.h" LinkedList::LinkedList() { head = NULL; } LinkedList::~LinkedList() { ListNode *tmp = head; while (tmp != NULL) { head = head->getNext(); delete tmp; tmp = head; } } void LinkedList::insertItem(ListNode::value_type item) { ListNode *newNode,*cur = head;
  • 4. newNode = new ListNode; newNode->setDatum(item); newNode->setNext(NULL); if (head == NULL) { head = newNode; } else { while (cur->getNext() != NULL) { cur = cur->getNext(); } cur->setNext(newNode); } } void LinkedList::makeList(const ListNode::value_type num[], const size_t& count) { int i = 0; while ( i < count) { insertItem(num[i++]); } } void LinkedList::deleteList() { ListNode *tmp = head; while (tmp != NULL) { head = head->getNext(); delete tmp; tmp = head; } } std::ostream& operator<<(std::ostream& os, const LinkedList &srcList) { //Set a current-pointer to the "head".
  • 5. ListNode* cursor = srcList.head; //While current-pointer is not NULL while (cursor != NULL) { //Print the data member ("datum") of the current node os << "->[" << cursor->getDatum() << "]"; //Set the current-pointer to the "next" node in the list. cursor = cursor->getNext(); } //Print out a basic termination symbol std::cout << "--X" << std::endl; return os; } --------------------------------------- //main.cpp #include #include "linkedlist.h" using namespace std; int main() { LinkedList list1; //Test of adding items out of order list1.insertItem(5); list1.insertItem(20); list1.insertItem(10); cout << "After adding 5,20,10 to list ,List contains" << endl; cout << list1 << endl; //Test of deleting entire list list1.deleteList(); cout << "After deleteing list,List contains" << endl; cout << list1 << endl; //Add items again in same order as before cout << "After adding 5,20,10 to list ,List contains" << endl; list1.insertItem(5); list1.insertItem(20); list1.insertItem(10); cout << list1 << endl;
  • 6. //Now replace list with a new one in a specific order int pow2[] = { 1, 2, 4, 8, 16, 32, 16, 8, 4, 2, 1 }; list1.makeList(pow2, sizeof(pow2) / sizeof(int)); cout << "After calling makeList function" << endl; cout << list1 << endl; //Returning a non-zero number, if not 3, then we know it seg-faulted return 3; } ----------------------------------------------------------------------------------------------------------- After adding 5,20,10 to list ,List contains ->[5]->[20]->[10]--X After deleteing list,List contains --X After adding 5,20,10 to list ,List contains ->[5]->[20]->[10]--X After calling makeList function ->[5]->[20]->[10]->[1]->[2]->[4]->[8]->[16]->[32]->[16]->[8]->[4]->[2]->[1]--X