SlideShare a Scribd company logo
1 of 9
Download to read offline
This assignment and the next (#5) involve design and development of a sequential
non contiguous and dynamic datastructure called LinkedList. A linked list object is
a container consisting of connected ListNode objects. As before, we are not going
to use pre-fabricated classes from the c++ library, but construct the LinkedList
ADT from scratch.
The first step is construction and testing of the ListNode class. A ListNode object
contains a data field and a pointer to the next ListNode object (note the recursive
definition).
#This assignment requires you to
1. Read the Assignment 4 Notes
2. Watch the Assignment 4 Support video
3. Implement the following methods of the ListNode class
-custom constructor
-setters for next pointer and data
4. Implement the insert and remove method in the main program
5. Scan the given template to find the above //TODO and implement the code
needed
//TODO in ListNodecpp.h file
public: ListNode(T idata, ListNode<T> * newNext);
public: void setNext(ListNode<T> * newNext);
public: void setData(T newData);
// TODO in main program
void remove(ListNode<int> * &front,int value)
void insert(ListNode<int> * &front,int value)
# The driver is given ListNodeMain.cpp is given to you that does the following
tests
1. Declares a pointer called front to point to a ListNode of datatype integer
2. Constructs four ListNodes with data 1,2,4 and adds them to form a linked
list.
3. Inserts ListNode with data 3 to the list
4. Removes node 1 and adds it back to test removing and adding the first
element
5. Removes node 3 to test removing a middle node
6. Removes node 4 to test removing the last node
7. Attempt to remove a non existent node
8. Remove all existing nodes to empty the list
9. Insert node 4 and then node 1 to test if insertions preserve order
10.Print the list
Main.cpp
#include <iostream>
#include "ListNodecpp.h"
// REMEMBER each ListNode has two parts : a data field
// and an address field. The address is either null or points to the next node
//in the chain
//Requires: integer value for searching, address of front
//Effects: traverses the list node chain starting from front until the end comparing search value
with listnode getData. Returns the original search value if found, if not adds +1 to indicate not
found
//Modifies: Nothing
int search(ListNode<int> * front, int value);
//Requires: integer value for inserting, address of front
//Effects: creates a new ListNode with value and inserts in proper position (increasing order)in
the chain. If chain is empty, adds to the beginning
//Modifies: front, if node is added at the beginning.
//Also changes the next pointer of the previous node to point to the
//newly inserted list node. the next pointer of the newly inserted pointer
//points to what was the next of the previous node.
//This way both previous and current links are adjusted
//******** NOTE the use of & in passing pointer to front as parameter -
// Why do you think this is needed ?**********
void insert(ListNode<int> * &front,int value);
//Requires: integer value for adding, address of front
//Effects:creates a new ListNode with value and inserts at the beginning
//Modifies:front, if node is added at the beginning.
void addNode(ListNode<int> * &front,int value);
//Requires: integer value for removing, address of front
//Effects: removes a node, if list is empty or node not found, removes nothing.
//Modifies: If the first node is removed, front is adjusted.
// if removal is at the end or middle, makes sure all nececssary links are updated.
void remove(ListNode<int>* & front, int value);
//Requires: address of front
//Effects: prints data of each node, by traversing the chain starting from the front using next
pointers.
//Modifies: nothing
void printList(ListNode<int> * front);
//GIVEN
int main() {
// Add 3 Nodes to the chain of ListNodes
//note AddNode method appends to the end so this will be out of order
// the order of the nodes is 1,2 , 4
//Create a daisy chain aka Linked List
//
ListNode<int> * front = nullptr;
printList(front);
std::cout<<"**********************n";
addNode(front,1);
printList(front);
std::cout<<"**********************n";
addNode(front,2);
printList(front);
std::cout<<"**********************n";
addNode(front,4);
printList(front);
std::cout<<"**********************n";
// the insert method inserts node with value 3 in place
insert(front,3);
printList(front);
std::cout<<"**********************n";
// remove the first, so front needs to point to second
remove(front, 1);
printList(front);
std::cout<<"**********************n";
// insert it back
insert(front,1);
printList(front);
std::cout<<"**********************n";
//remove from the middle
remove(front, 3);
printList(front);
std::cout<<"**********************n";
// remove at the end
remove(front, 4);
printList(front);
std::cout<<"**********************n";
//remove a non existent node
remove(front, 5);
printList(front);
std::cout<<"**********************n";
// remove all nodes one by one leaving only front pointing to null pointer
remove(front, 2);
printList(front);
std::cout<<"**********************n";
remove(front, 1);
printList(front);
std::cout<<"**********************n";
// insert at the beginning of the empty list a larger value
insert(front, 4);
printList(front);
std::cout<<"**********************n";
// insert the smaller value at correct position in the front of the chain and change front
insert(front, 1);
printList(front);
std::cout<<"**********************n";
}
//GIVEN
void printList(ListNode<int> * front){
ListNode<int> * current = front;
while (current!=nullptr){
std::cout<<current->getData()<<"n";
current=current->getNext();
}
if (front ==nullptr)
std::cout<<"EMPTY LIST n";
}
//GIVEN
//searches the nodes starting from front, all the way to the end
// trying to match the given value with the data in the node.
// if found, it returns the value indicting found
//other wise it returns value +1 as a signal that item is not found
int search(ListNode<int> * front,int value){
ListNode<int> * current = front;
while (current!=nullptr&& current->getData()!=value){
// std::cout<<current->getData()<<"n";
current=current->getNext();
}
if (current!= nullptr) return current->getData();
return value+1 ; //
// to indicate not found.
//The calling program checks if return value is the same as search value
// to know if its found; I was using *-1 but if search value is 0, then that does not work;
}
//GIVEN
//creates a new node with data == value
void addNode(ListNode<int> * & front ,int value){
ListNode<int> * current = front;
ListNode<int> * temp = new ListNode<int>(value);
if (front ==nullptr)
front=temp;
else {
while (current->getNext()!=nullptr){
// std::cout<<current->getData()<<"n";
current=current->getNext();
}
//ListNode<int> * temp = new ListNode<int>(value);
current->setNext(temp);
}
}
//GIVEN TO YOU
//remove the node that has the given integer value in its data field
void remove(ListNode<int> * &front,int value){
// we NEVER change front, unless the first item is deleted or
//an item is added to the front of the list
ListNode<int> * current = front; // save the front in current
ListNode<int> * previous=current;// save the front as previous
//initially both current and previous will point to front
//then previous will lag behind current
//keep moving along the list by following the next pointer
//until either the item is found or we reach the end of the list
while (current!=nullptr&& current->getData()!=value){
previous = current;
current=current->getNext();
}
//if the item is found in the middle or end of the list
//then remove the item by skipping over it
//is setting the next of the previous to the next of the current
if (current!= nullptr&&current->getData()==value) {
previous->setNext(current->getNext());
//if found at the beginning, front needs to be changed to next of current
if (current->getData()==front->getData()){
front=current->getNext();
delete current;//release and deallocate the deleted note
current=nullptr;//set the pointer to null so its not pointing to junk
}
}
}
//TODO
//TODO - USE THE REMOVE ALGORITHM to help you
// to set current and previous links according
void insert(ListNode<int> * &front,int value){
//TODO
}
ListNode.h
#include<memory>
#include <string>
template <class T>
// We can create a linked list wich contains items of type T
// in our assignments T will be either integer or Song
//template <class T>
class ListNode{
public: T data; // the data field in our case would contain
//either an integer a Song
public: ListNode * next; // this is a pointer to the next integer or Song
// default constructor constructs a node with
//data value as the default data value for T and null link
public: ListNode();
// custom constructor #1 constructs a node with data value == data
// and next== null
public: ListNode(T data);
//custom constructor #2
//constructs a node with data value = idata and next == newNext
public: ListNode(T idata, ListNode<T> * newNext);
public:std::string toString();
//get the address of the next integer or Song
public: ListNode<T> * getNext();
//change the next address to newNext
public: void setNext(ListNode<T> * newNext);
//return the integer or Song
public: T getData();
//change the Song to newData
public: void setData(T newData);
};
Listnodecpp.h
#include<memory>
#include <string>
template <class T>
// We can create a linked list wich contains items of type T
// in our assignments T will be either integer or Song
//template <class T>
class ListNode{
public: T data; // the data field in our case would contain
//either an integer a Song
public: ListNode * next; // this is a pointer to the next integer or Song
// default constructor constructs a node with
//data value as the default data value for T and null link
public: ListNode();
// custom constructor #1 constructs a node with data value == data
// and next== null
public: ListNode(T data);
//custom constructor #2
//constructs a node with data value = idata and next == newNext
public: ListNode(T idata, ListNode<T> * newNext);
public:std::string toString();
//get the address of the next integer or Song
public: ListNode<T> * getNext();
//change the next address to newNext
public: void setNext(ListNode<T> * newNext);
//return the integer or Song
public: T getData();
//change the Song to newData
public: void setData(T newData);
};
makefile
all:
g++ main.cpp ListNode.h ListNodecpp.h -o ListNodeChain
output.txt
EMPTY LIST
**********************
1
**********************
1
2
**********************
1
2
4
**********************
1
2
3
4
**********************
2
3
4
**********************
1
2
3
4
**********************
1
2
4
**********************
1
2
**********************
1
2
**********************
1
**********************
EMPTY LIST
**********************
4
**********************
1
4
**********************
This assignment and the next (#5) involve design and development of a.pdf

More Related Content

Similar to This assignment and the next (#5) involve design and development of a.pdf

How to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfHow to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfarihantelehyb
 
Write an algorithm that reads a list of integers from the keyboard, .pdf
Write an algorithm that reads a list of integers from the keyboard, .pdfWrite an algorithm that reads a list of integers from the keyboard, .pdf
Write an algorithm that reads a list of integers from the keyboard, .pdfArrowdeepak
 
Consider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfConsider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfsales98
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfJUSTSTYLISH3B2MOHALI
 
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 Sorted number list implementation with linked listsStep 1 Inspec.pdf Sorted number list implementation with linked listsStep 1 Inspec.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdfalmaniaeyewear
 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfankit11134
 
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-.pdfvishalateen
 
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.pdffortmdu
 
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.pdfpoblettesedanoree498
 
C++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxC++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxMatthPYNashd
 
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdfDividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdftesmondday29076
 
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.docxgilliandunce53776
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfezonesolutions
 
Write java program using linked list to get integer from user and.docx
 Write java program using linked list to get integer from user and.docx Write java program using linked list to get integer from user and.docx
Write java program using linked list to get integer from user and.docxajoy21
 
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.docxmckellarhastings
 

Similar to This assignment and the next (#5) involve design and development of a.pdf (20)

DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
 
How to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfHow to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdf
 
Write an algorithm that reads a list of integers from the keyboard, .pdf
Write an algorithm that reads a list of integers from the keyboard, .pdfWrite an algorithm that reads a list of integers from the keyboard, .pdf
Write an algorithm that reads a list of integers from the keyboard, .pdf
 
Consider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfConsider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdf
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 Sorted number list implementation with linked listsStep 1 Inspec.pdf Sorted number list implementation with linked listsStep 1 Inspec.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdf
 
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
 
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++ 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
 
C++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxC++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docx
 
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdfDividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.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
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdf
 
Write java program using linked list to get integer from user and.docx
 Write java program using linked list to get integer from user and.docx Write java program using linked list to get integer from user and.docx
Write java program using linked list to get integer from user and.docx
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
 
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
 

More from EricvtJFraserr

Trade protectionism is a policy that protects domestic industries from.pdf
Trade protectionism is a policy that protects domestic industries from.pdfTrade protectionism is a policy that protects domestic industries from.pdf
Trade protectionism is a policy that protects domestic industries from.pdfEricvtJFraserr
 
trace a calciol molecule (inactive D) from the liver to the kidney- Th.pdf
trace a calciol molecule (inactive D) from the liver to the kidney- Th.pdftrace a calciol molecule (inactive D) from the liver to the kidney- Th.pdf
trace a calciol molecule (inactive D) from the liver to the kidney- Th.pdfEricvtJFraserr
 
TP fraudulently failed to report income that resulted in a $100-000 un.pdf
TP fraudulently failed to report income that resulted in a $100-000 un.pdfTP fraudulently failed to report income that resulted in a $100-000 un.pdf
TP fraudulently failed to report income that resulted in a $100-000 un.pdfEricvtJFraserr
 
Topographic Maps 1- Define topographic map- 2- Describe 3 different.pdf
Topographic Maps 1-  Define topographic map-  2-  Describe 3 different.pdfTopographic Maps 1-  Define topographic map-  2-  Describe 3 different.pdf
Topographic Maps 1- Define topographic map- 2- Describe 3 different.pdfEricvtJFraserr
 
Topic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdf
Topic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdfTopic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdf
Topic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdfEricvtJFraserr
 
Total tactory overlisad is $1-200-000- Ansume tho following activity c.pdf
Total tactory overlisad is $1-200-000- Ansume tho following activity c.pdfTotal tactory overlisad is $1-200-000- Ansume tho following activity c.pdf
Total tactory overlisad is $1-200-000- Ansume tho following activity c.pdfEricvtJFraserr
 
Topographic Maps 10- What is the scale of a map- Give some examples.pdf
Topographic Maps  10-  What is the scale of a map-  Give some examples.pdfTopographic Maps  10-  What is the scale of a map-  Give some examples.pdf
Topographic Maps 10- What is the scale of a map- Give some examples.pdfEricvtJFraserr
 
Toast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdf
Toast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdfToast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdf
Toast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdfEricvtJFraserr
 
To do- Use the drop down list in column E to determine which entity ty.pdf
To do- Use the drop down list in column E to determine which entity ty.pdfTo do- Use the drop down list in column E to determine which entity ty.pdf
To do- Use the drop down list in column E to determine which entity ty.pdfEricvtJFraserr
 
To determine the mechanism by which N-WASp mediates activation by Cdc4.pdf
To determine the mechanism by which N-WASp mediates activation by Cdc4.pdfTo determine the mechanism by which N-WASp mediates activation by Cdc4.pdf
To determine the mechanism by which N-WASp mediates activation by Cdc4.pdfEricvtJFraserr
 
To clarify- this is specifically for Java- Write a program that asks t.pdf
To clarify- this is specifically for Java- Write a program that asks t.pdfTo clarify- this is specifically for Java- Write a program that asks t.pdf
To clarify- this is specifically for Java- Write a program that asks t.pdfEricvtJFraserr
 
To avoid typos- copy and paste the portions of the IP address that wil.pdf
To avoid typos- copy and paste the portions of the IP address that wil.pdfTo avoid typos- copy and paste the portions of the IP address that wil.pdf
To avoid typos- copy and paste the portions of the IP address that wil.pdfEricvtJFraserr
 
Three Ways Heat Energy can move from one place to another (Define and.pdf
Three Ways Heat Energy can move from one place to another (Define and.pdfThree Ways Heat Energy can move from one place to another (Define and.pdf
Three Ways Heat Energy can move from one place to another (Define and.pdfEricvtJFraserr
 
This year Luke has calculated his gross tax liability at $1-900- Luke.pdf
This year Luke has calculated his gross tax liability at $1-900- Luke.pdfThis year Luke has calculated his gross tax liability at $1-900- Luke.pdf
This year Luke has calculated his gross tax liability at $1-900- Luke.pdfEricvtJFraserr
 
This Scottish economist was highly critical of the Mercantilists- A-Ad.pdf
This Scottish economist was highly critical of the Mercantilists- A-Ad.pdfThis Scottish economist was highly critical of the Mercantilists- A-Ad.pdf
This Scottish economist was highly critical of the Mercantilists- A-Ad.pdfEricvtJFraserr
 
This map shows the location and size of earthquakes in and around Turk.pdf
This map shows the location and size of earthquakes in and around Turk.pdfThis map shows the location and size of earthquakes in and around Turk.pdf
This map shows the location and size of earthquakes in and around Turk.pdfEricvtJFraserr
 
This medieval social- cultural- and economic movement that involved de.pdf
This medieval social- cultural- and economic movement that involved de.pdfThis medieval social- cultural- and economic movement that involved de.pdf
This medieval social- cultural- and economic movement that involved de.pdfEricvtJFraserr
 
This map shows a summary of earthquakes that occurred across the globe.pdf
This map shows a summary of earthquakes that occurred across the globe.pdfThis map shows a summary of earthquakes that occurred across the globe.pdf
This map shows a summary of earthquakes that occurred across the globe.pdfEricvtJFraserr
 
This map from the USGS' Earthquake Hazards Program website shows earth.pdf
This map from the USGS' Earthquake Hazards Program website shows earth.pdfThis map from the USGS' Earthquake Hazards Program website shows earth.pdf
This map from the USGS' Earthquake Hazards Program website shows earth.pdfEricvtJFraserr
 
Things wrong with my code- 1- The notes do not play when i press down.pdf
Things wrong with my code- 1- The notes do not play when i press down.pdfThings wrong with my code- 1- The notes do not play when i press down.pdf
Things wrong with my code- 1- The notes do not play when i press down.pdfEricvtJFraserr
 

More from EricvtJFraserr (20)

Trade protectionism is a policy that protects domestic industries from.pdf
Trade protectionism is a policy that protects domestic industries from.pdfTrade protectionism is a policy that protects domestic industries from.pdf
Trade protectionism is a policy that protects domestic industries from.pdf
 
trace a calciol molecule (inactive D) from the liver to the kidney- Th.pdf
trace a calciol molecule (inactive D) from the liver to the kidney- Th.pdftrace a calciol molecule (inactive D) from the liver to the kidney- Th.pdf
trace a calciol molecule (inactive D) from the liver to the kidney- Th.pdf
 
TP fraudulently failed to report income that resulted in a $100-000 un.pdf
TP fraudulently failed to report income that resulted in a $100-000 un.pdfTP fraudulently failed to report income that resulted in a $100-000 un.pdf
TP fraudulently failed to report income that resulted in a $100-000 un.pdf
 
Topographic Maps 1- Define topographic map- 2- Describe 3 different.pdf
Topographic Maps 1-  Define topographic map-  2-  Describe 3 different.pdfTopographic Maps 1-  Define topographic map-  2-  Describe 3 different.pdf
Topographic Maps 1- Define topographic map- 2- Describe 3 different.pdf
 
Topic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdf
Topic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdfTopic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdf
Topic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdf
 
Total tactory overlisad is $1-200-000- Ansume tho following activity c.pdf
Total tactory overlisad is $1-200-000- Ansume tho following activity c.pdfTotal tactory overlisad is $1-200-000- Ansume tho following activity c.pdf
Total tactory overlisad is $1-200-000- Ansume tho following activity c.pdf
 
Topographic Maps 10- What is the scale of a map- Give some examples.pdf
Topographic Maps  10-  What is the scale of a map-  Give some examples.pdfTopographic Maps  10-  What is the scale of a map-  Give some examples.pdf
Topographic Maps 10- What is the scale of a map- Give some examples.pdf
 
Toast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdf
Toast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdfToast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdf
Toast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdf
 
To do- Use the drop down list in column E to determine which entity ty.pdf
To do- Use the drop down list in column E to determine which entity ty.pdfTo do- Use the drop down list in column E to determine which entity ty.pdf
To do- Use the drop down list in column E to determine which entity ty.pdf
 
To determine the mechanism by which N-WASp mediates activation by Cdc4.pdf
To determine the mechanism by which N-WASp mediates activation by Cdc4.pdfTo determine the mechanism by which N-WASp mediates activation by Cdc4.pdf
To determine the mechanism by which N-WASp mediates activation by Cdc4.pdf
 
To clarify- this is specifically for Java- Write a program that asks t.pdf
To clarify- this is specifically for Java- Write a program that asks t.pdfTo clarify- this is specifically for Java- Write a program that asks t.pdf
To clarify- this is specifically for Java- Write a program that asks t.pdf
 
To avoid typos- copy and paste the portions of the IP address that wil.pdf
To avoid typos- copy and paste the portions of the IP address that wil.pdfTo avoid typos- copy and paste the portions of the IP address that wil.pdf
To avoid typos- copy and paste the portions of the IP address that wil.pdf
 
Three Ways Heat Energy can move from one place to another (Define and.pdf
Three Ways Heat Energy can move from one place to another (Define and.pdfThree Ways Heat Energy can move from one place to another (Define and.pdf
Three Ways Heat Energy can move from one place to another (Define and.pdf
 
This year Luke has calculated his gross tax liability at $1-900- Luke.pdf
This year Luke has calculated his gross tax liability at $1-900- Luke.pdfThis year Luke has calculated his gross tax liability at $1-900- Luke.pdf
This year Luke has calculated his gross tax liability at $1-900- Luke.pdf
 
This Scottish economist was highly critical of the Mercantilists- A-Ad.pdf
This Scottish economist was highly critical of the Mercantilists- A-Ad.pdfThis Scottish economist was highly critical of the Mercantilists- A-Ad.pdf
This Scottish economist was highly critical of the Mercantilists- A-Ad.pdf
 
This map shows the location and size of earthquakes in and around Turk.pdf
This map shows the location and size of earthquakes in and around Turk.pdfThis map shows the location and size of earthquakes in and around Turk.pdf
This map shows the location and size of earthquakes in and around Turk.pdf
 
This medieval social- cultural- and economic movement that involved de.pdf
This medieval social- cultural- and economic movement that involved de.pdfThis medieval social- cultural- and economic movement that involved de.pdf
This medieval social- cultural- and economic movement that involved de.pdf
 
This map shows a summary of earthquakes that occurred across the globe.pdf
This map shows a summary of earthquakes that occurred across the globe.pdfThis map shows a summary of earthquakes that occurred across the globe.pdf
This map shows a summary of earthquakes that occurred across the globe.pdf
 
This map from the USGS' Earthquake Hazards Program website shows earth.pdf
This map from the USGS' Earthquake Hazards Program website shows earth.pdfThis map from the USGS' Earthquake Hazards Program website shows earth.pdf
This map from the USGS' Earthquake Hazards Program website shows earth.pdf
 
Things wrong with my code- 1- The notes do not play when i press down.pdf
Things wrong with my code- 1- The notes do not play when i press down.pdfThings wrong with my code- 1- The notes do not play when i press down.pdf
Things wrong with my code- 1- The notes do not play when i press down.pdf
 

Recently uploaded

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)Dr. Mazin Mohamed alkathiri
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 

Recently uploaded (20)

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 

This assignment and the next (#5) involve design and development of a.pdf

  • 1. This assignment and the next (#5) involve design and development of a sequential non contiguous and dynamic datastructure called LinkedList. A linked list object is a container consisting of connected ListNode objects. As before, we are not going to use pre-fabricated classes from the c++ library, but construct the LinkedList ADT from scratch. The first step is construction and testing of the ListNode class. A ListNode object contains a data field and a pointer to the next ListNode object (note the recursive definition). #This assignment requires you to 1. Read the Assignment 4 Notes 2. Watch the Assignment 4 Support video 3. Implement the following methods of the ListNode class -custom constructor -setters for next pointer and data 4. Implement the insert and remove method in the main program 5. Scan the given template to find the above //TODO and implement the code needed //TODO in ListNodecpp.h file public: ListNode(T idata, ListNode<T> * newNext); public: void setNext(ListNode<T> * newNext); public: void setData(T newData); // TODO in main program void remove(ListNode<int> * &front,int value) void insert(ListNode<int> * &front,int value) # The driver is given ListNodeMain.cpp is given to you that does the following tests 1. Declares a pointer called front to point to a ListNode of datatype integer 2. Constructs four ListNodes with data 1,2,4 and adds them to form a linked list. 3. Inserts ListNode with data 3 to the list 4. Removes node 1 and adds it back to test removing and adding the first element 5. Removes node 3 to test removing a middle node 6. Removes node 4 to test removing the last node 7. Attempt to remove a non existent node 8. Remove all existing nodes to empty the list 9. Insert node 4 and then node 1 to test if insertions preserve order 10.Print the list Main.cpp #include <iostream>
  • 2. #include "ListNodecpp.h" // REMEMBER each ListNode has two parts : a data field // and an address field. The address is either null or points to the next node //in the chain //Requires: integer value for searching, address of front //Effects: traverses the list node chain starting from front until the end comparing search value with listnode getData. Returns the original search value if found, if not adds +1 to indicate not found //Modifies: Nothing int search(ListNode<int> * front, int value); //Requires: integer value for inserting, address of front //Effects: creates a new ListNode with value and inserts in proper position (increasing order)in the chain. If chain is empty, adds to the beginning //Modifies: front, if node is added at the beginning. //Also changes the next pointer of the previous node to point to the //newly inserted list node. the next pointer of the newly inserted pointer //points to what was the next of the previous node. //This way both previous and current links are adjusted //******** NOTE the use of & in passing pointer to front as parameter - // Why do you think this is needed ?********** void insert(ListNode<int> * &front,int value); //Requires: integer value for adding, address of front //Effects:creates a new ListNode with value and inserts at the beginning //Modifies:front, if node is added at the beginning. void addNode(ListNode<int> * &front,int value); //Requires: integer value for removing, address of front //Effects: removes a node, if list is empty or node not found, removes nothing. //Modifies: If the first node is removed, front is adjusted. // if removal is at the end or middle, makes sure all nececssary links are updated. void remove(ListNode<int>* & front, int value); //Requires: address of front //Effects: prints data of each node, by traversing the chain starting from the front using next pointers. //Modifies: nothing void printList(ListNode<int> * front); //GIVEN int main() { // Add 3 Nodes to the chain of ListNodes //note AddNode method appends to the end so this will be out of order
  • 3. // the order of the nodes is 1,2 , 4 //Create a daisy chain aka Linked List // ListNode<int> * front = nullptr; printList(front); std::cout<<"**********************n"; addNode(front,1); printList(front); std::cout<<"**********************n"; addNode(front,2); printList(front); std::cout<<"**********************n"; addNode(front,4); printList(front); std::cout<<"**********************n"; // the insert method inserts node with value 3 in place insert(front,3); printList(front); std::cout<<"**********************n"; // remove the first, so front needs to point to second remove(front, 1); printList(front); std::cout<<"**********************n"; // insert it back insert(front,1); printList(front); std::cout<<"**********************n"; //remove from the middle remove(front, 3); printList(front); std::cout<<"**********************n"; // remove at the end remove(front, 4); printList(front); std::cout<<"**********************n"; //remove a non existent node remove(front, 5); printList(front); std::cout<<"**********************n"; // remove all nodes one by one leaving only front pointing to null pointer remove(front, 2); printList(front); std::cout<<"**********************n"; remove(front, 1); printList(front); std::cout<<"**********************n";
  • 4. // insert at the beginning of the empty list a larger value insert(front, 4); printList(front); std::cout<<"**********************n"; // insert the smaller value at correct position in the front of the chain and change front insert(front, 1); printList(front); std::cout<<"**********************n"; } //GIVEN void printList(ListNode<int> * front){ ListNode<int> * current = front; while (current!=nullptr){ std::cout<<current->getData()<<"n"; current=current->getNext(); } if (front ==nullptr) std::cout<<"EMPTY LIST n"; } //GIVEN //searches the nodes starting from front, all the way to the end // trying to match the given value with the data in the node. // if found, it returns the value indicting found //other wise it returns value +1 as a signal that item is not found int search(ListNode<int> * front,int value){ ListNode<int> * current = front; while (current!=nullptr&& current->getData()!=value){ // std::cout<<current->getData()<<"n"; current=current->getNext(); } if (current!= nullptr) return current->getData(); return value+1 ; // // to indicate not found. //The calling program checks if return value is the same as search value // to know if its found; I was using *-1 but if search value is 0, then that does not work; } //GIVEN //creates a new node with data == value void addNode(ListNode<int> * & front ,int value){ ListNode<int> * current = front; ListNode<int> * temp = new ListNode<int>(value);
  • 5. if (front ==nullptr) front=temp; else { while (current->getNext()!=nullptr){ // std::cout<<current->getData()<<"n"; current=current->getNext(); } //ListNode<int> * temp = new ListNode<int>(value); current->setNext(temp); } } //GIVEN TO YOU //remove the node that has the given integer value in its data field void remove(ListNode<int> * &front,int value){ // we NEVER change front, unless the first item is deleted or //an item is added to the front of the list ListNode<int> * current = front; // save the front in current ListNode<int> * previous=current;// save the front as previous //initially both current and previous will point to front //then previous will lag behind current //keep moving along the list by following the next pointer //until either the item is found or we reach the end of the list while (current!=nullptr&& current->getData()!=value){ previous = current; current=current->getNext(); } //if the item is found in the middle or end of the list //then remove the item by skipping over it //is setting the next of the previous to the next of the current if (current!= nullptr&&current->getData()==value) { previous->setNext(current->getNext()); //if found at the beginning, front needs to be changed to next of current if (current->getData()==front->getData()){ front=current->getNext(); delete current;//release and deallocate the deleted note current=nullptr;//set the pointer to null so its not pointing to junk } }
  • 6. } //TODO //TODO - USE THE REMOVE ALGORITHM to help you // to set current and previous links according void insert(ListNode<int> * &front,int value){ //TODO } ListNode.h #include<memory> #include <string> template <class T> // We can create a linked list wich contains items of type T // in our assignments T will be either integer or Song //template <class T> class ListNode{ public: T data; // the data field in our case would contain //either an integer a Song public: ListNode * next; // this is a pointer to the next integer or Song // default constructor constructs a node with //data value as the default data value for T and null link public: ListNode(); // custom constructor #1 constructs a node with data value == data // and next== null public: ListNode(T data); //custom constructor #2 //constructs a node with data value = idata and next == newNext public: ListNode(T idata, ListNode<T> * newNext); public:std::string toString(); //get the address of the next integer or Song public: ListNode<T> * getNext(); //change the next address to newNext public: void setNext(ListNode<T> * newNext); //return the integer or Song public: T getData(); //change the Song to newData public: void setData(T newData);
  • 7. }; Listnodecpp.h #include<memory> #include <string> template <class T> // We can create a linked list wich contains items of type T // in our assignments T will be either integer or Song //template <class T> class ListNode{ public: T data; // the data field in our case would contain //either an integer a Song public: ListNode * next; // this is a pointer to the next integer or Song // default constructor constructs a node with //data value as the default data value for T and null link public: ListNode(); // custom constructor #1 constructs a node with data value == data // and next== null public: ListNode(T data); //custom constructor #2 //constructs a node with data value = idata and next == newNext public: ListNode(T idata, ListNode<T> * newNext); public:std::string toString(); //get the address of the next integer or Song public: ListNode<T> * getNext(); //change the next address to newNext public: void setNext(ListNode<T> * newNext); //return the integer or Song public: T getData(); //change the Song to newData public: void setData(T newData); }; makefile all: g++ main.cpp ListNode.h ListNodecpp.h -o ListNodeChain output.txt EMPTY LIST **********************