SlideShare a Scribd company logo
1 of 15
Download to read offline
Change the driver file (the main .cpp) so that it asks the user to enter the values, then prints them,
reverses them, and prints them again. DO NOT USE THE revprint2 function that is in the code!
LinkListImp.cpp
//----- List.cpp -----
#include
using namespace std;
#include "linkedlist.h"
//-- Definition of the class constructor
List::List()
: first(0), mySize(0)
{ }
//-- Definition of the copy constructor
List::List(const List & origList)
{
mySize = origList.mySize;
first = 0;
if (mySize == 0) return;
List::NodePointer origPtr, lastPtr;
first = new Node(origList.first->data); // copy first node
lastPtr = first;
origPtr = origList.first->next;
while (origPtr != 0)
{
lastPtr->next = new Node(origPtr->data);
origPtr = origPtr->next;
lastPtr = lastPtr->next;
}
}
//-- Definition of the destructor
inline List::~List()
{
List::NodePointer prev = first,
ptr;
while (prev != 0)
{
ptr = prev->next;
delete prev;
prev = ptr;
}
}
// Definition of empty()
bool List::empty()
{
return mySize == 0;
}
//-- Definition of the assignment operator
const List & List::operator=(const List & rightSide)
{
mySize = rightSide.mySize;
first = 0;
if (mySize == 0) return *this;
if (this != &rightSide)
{
this->~List();
List::NodePointer origPtr, lastPtr;
first = new Node(rightSide.first->data); // copy first node
lastPtr = first;
origPtr = rightSide.first->next;
while (origPtr != 0)
{
lastPtr->next = new Node(origPtr->data);
origPtr = origPtr->next;
lastPtr = lastPtr->next;
}
}
return *this;
}
//-- Definition of insert()
void List::insert(ElementType dataVal, int index)
{
if (index < 0 || index > mySize)
{
cerr << "Illegal location to insert -- " << index << endl;
return;
}
mySize++;
List::NodePointer newPtr = new Node(dataVal),
predPtr = first;
if (index == 0)
{
newPtr->next = first;
first = newPtr;
}
else
{
for (int i = 1; i < index; i++)
predPtr = predPtr->next;
newPtr->next = predPtr->next;
predPtr->next = newPtr;
}
}
//-- Definition of erase()
void List::erase(int index)
{
if (index < 0 || index >= mySize)
{
cerr << "Illegal location to delete -- " << index << endl;
return;
}
mySize--;
List::NodePointer ptr,
predPtr = first;
if (index == 0)
{
ptr = first;
first = ptr->next;
delete ptr;
}
else
{
for (int i = 1; i < index; i++)
predPtr = predPtr->next;
ptr = predPtr->next;
predPtr->next = ptr->next;
delete ptr;
}
}
//-- Definition of search()
int List::search(ElementType dataVal)
{
int loc;
List::NodePointer tempP = first;
for (loc = 0; loc < mySize; loc++)
if (tempP->data == dataVal)
return loc;
else
tempP = tempP->next;
return -1;
}
//-- Definition of display()
void List::display(ostream & out) const
{
NodePointer ptr = first;
while (ptr != 0)
{
out << ptr->data << " ";
ptr = ptr->next;
}
}
void List::revPrint(ostream & out)
{
reverse();
display(out);
reverse();
}
void List::revPrint2(ostream &out, NodePointer ptr)
{
out << "Inside revPrint2 ";
static List::NodePointer point = first;
out << point->data << endl;
if (point != NULL)
{
out << "Inside if statement ";
revPrint2(out, point->next);
out << point->data;
}
}
//-- Definition of the output operator
ostream & operator<<(ostream & out, const List & aList)
{
aList.display(out);
return out;
}
//-- Definition of nodeCount()
int List::nodeCount()
{ // or simply, { return mySize; }
int count = 0;
List::NodePointer ptr = first;
while (ptr != 0)
{
count++;
ptr = ptr->next;
}
return count;
}
//-- Definition of reverse()
void List::reverse()
{
}
//-- Definition of ascendingOrder()
bool List::ascendingOrder()
{
if (mySize <= 1)
//empty or one element list
return true;
//else
NodePointer prevP = first,
tempP = first->next;
while (tempP != 0 && prevP->data <= tempP->data)
{
prevP = tempP;
tempP = tempP->next;
}
if (tempP != 0)
return false;
// else
return true;
}
linkedlist.cpp
#include
using namespace std;
#include "linkedlist.h"
int main()
{
List mylist;
for (int i = 0; i < 6; i++)
mylist.insert(i * 2, i);
mylist.display(cout);
cout << endl;
mylist.revPrint(cout);
cout << endl;
cout << mylist;
}
linkedlist.h
//----- List.h -----
#ifndef LINKEDLIST
#define LINKEDLIST
#include
using namespace std;
typedef int ElementType;
class List
{
private:
class Node
{
public:
ElementType data;
Node * next;
Node()
: next(0)
{ }
Node(ElementType dataValue)
: data(dataValue), next(0)
{ }
}; //--- end of Node class
typedef Node * NodePointer;
public:
//------ List OPERATIONS
List();
List(const List & origList);
~List();
const List & operator=(const List & rightSide);
bool List::empty();
void insert(ElementType dataVal, int index);
void erase(int index);
int search(ElementType dataVal);
void display(ostream & out) const;
void revPrint(ostream & out);
void revPrint2(ostream &out, NodePointer ptr = NULL);
int nodeCount();
void reverse();
bool ascendingOrder();
private:
//------ DATA MEMBERS
NodePointer first ;
int mySize;
}; //--- end of List class
ostream & operator<<(ostream & out, const List & aList);
//istream & operator>>(istream & in, List & aList);
#endif
Solution
////----- List.cpp -----
//added reverse functionality
#include
using namespace std;
#include "linkedlist.h"
//-- Definition of the class constructor
List::List()
: first(0), mySize(0)
{ }
//-- Definition of the copy constructor
List::List(const List & origList)
{
mySize = origList.mySize;
first = 0;
if (mySize == 0) return;
List::NodePointer origPtr, lastPtr;
first = new Node(origList.first->data); // copy first node
lastPtr = first;
origPtr = origList.first->next;
while (origPtr != 0)
{
lastPtr->next = new Node(origPtr->data);
origPtr = origPtr->next;
lastPtr = lastPtr->next;
}
}
//-- Definition of the destructor
inline List::~List()
{
List::NodePointer prev = first,
ptr;
while (prev != 0)
{
ptr = prev->next;
delete prev;
prev = ptr;
}
}
// Definition of empty()
bool List::empty()
{
return mySize == 0;
}
//-- Definition of the assignment operator
const List & List::operator=(const List & rightSide)
{
mySize = rightSide.mySize;
first = 0;
if (mySize == 0) return *this;
if (this != &rightSide)
{
this->~List();
List::NodePointer origPtr, lastPtr;
first = new Node(rightSide.first->data); // copy first node
lastPtr = first;
origPtr = rightSide.first->next;
while (origPtr != 0)
{
lastPtr->next = new Node(origPtr->data);
origPtr = origPtr->next;
lastPtr = lastPtr->next;
}
}
return *this;
}
//-- Definition of insert()
void List::insert(ElementType dataVal, int index)
{
if (index < 0 || index > mySize)
{
cerr << "Illegal location to insert -- " << index << endl;
return;
}
mySize++;
List::NodePointer newPtr = new Node(dataVal),
predPtr = first;
if (index == 0)
{
newPtr->next = first;
first = newPtr;
}
else
{
for (int i = 1; i < index; i++)
predPtr = predPtr->next;
newPtr->next = predPtr->next;
predPtr->next = newPtr;
}
}
//-- Definition of erase()
void List::erase(int index)
{
if (index < 0 || index >= mySize)
{
cerr << "Illegal location to delete -- " << index << endl;
return;
}
mySize--;
List::NodePointer ptr,
predPtr = first;
if (index == 0)
{
ptr = first;
first = ptr->next;
delete ptr;
}
else
{
for (int i = 1; i < index; i++)
predPtr = predPtr->next;
ptr = predPtr->next;
predPtr->next = ptr->next;
delete ptr;
}
}
//-- Definition of search()
int List::search(ElementType dataVal)
{
int loc;
List::NodePointer tempP = first;
for (loc = 0; loc < mySize; loc++)
if (tempP->data == dataVal)
return loc;
else
tempP = tempP->next;
return -1;
}
//-- Definition of display()
void List::display(ostream & out) const
{
NodePointer ptr = first;
while (ptr != 0)
{
out << ptr->data << " ";
ptr = ptr->next;
}
}
void List::revPrint(ostream & out)
{
reverse();
display(out);
reverse();
}
void List::revPrint2(ostream &out, NodePointer ptr)
{
out << "Inside revPrint2 ";
static List::NodePointer point = first;
out << point->data << endl;
if (point != NULL)
{
out << "Inside if statement ";
revPrint2(out, point->next);
out << point->data;
}
}
//-- Definition of the output operator
ostream & operator<<(ostream & out, const List & aList)
{
aList.display(out);
return out;
}
//-- Definition of nodeCount()
int List::nodeCount()
{ // or simply, { return mySize; }
int count = 0;
List::NodePointer ptr = first;
while (ptr != 0)
{
count++;
ptr = ptr->next;
}
return count;
}
//-- Definition of reverse()
//added by chegg EA
void List::reverse()
{
static List::NodePointer current,next,prev;
prev = NULL;
current = first;
while (current != NULL)
{
next = current->next;
current->next = prev;
prev = current;
current = next;
}
first= prev;
}
//-- Definition of ascendingOrder()
bool List::ascendingOrder()
{
if (mySize <= 1)
//empty or one element list
return true;
//else
NodePointer prevP = first,
tempP = first->next;
while (tempP != 0 && prevP->data <= tempP->data)
{
prevP = tempP;
tempP = tempP->next;
}
if (tempP != 0)
return false;
// else
return true;
}
------------------------------------------------------------------------
// List.h
this file unchanged
---------------------------------------------------------------
//main.cpp
#include
using namespace std;
#include "linkedlist.h"
int main()
{
List mylist;
int num;
for (int i = 0; i < 6; i++)
{
//mylist.insert(i * 2, i);
//added by chegg EA,ask for user input
cin >> num;
mylist.insert(num, i);
}
cout << "mylist: ";
mylist.display(cout);
cout << endl;
//mylist.revPrint(cout);
//added by chegg EA,reverse the list
mylist.reverse();
//added by chegg EA, print the reversed list
cout << endl;
cout << "After reversing the list: "<

More Related Content

Similar to Change the driver file (the main .cpp) so that it asks the user to e.pdf

C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfcallawaycorb73779
 
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
 #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdfangelsfashion1
 
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdfAnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdfanwarsadath111
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptxchin463670
 
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
 
GIVEN CODE template -typename T- class DList { private- struct Node {.docx
GIVEN CODE template -typename T- class DList { private- struct Node {.docxGIVEN CODE template -typename T- class DList { private- struct Node {.docx
GIVEN CODE template -typename T- class DList { private- struct Node {.docxLeonardN9WWelchw
 
include ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfinclude ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfnaslin841216
 
DS - Application of List
DS - Application of ListDS - Application of List
DS - Application of ListMythiliMurugan3
 
CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1SIMONTHOMAS S
 
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
 
I have to write a polynomial class linked list program and i do not .pdf
I have to write a polynomial class linked list program and i do not .pdfI have to write a polynomial class linked list program and i do not .pdf
I have to write a polynomial class linked list program and i do not .pdfjibinsh
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfforladies
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfimplement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfFOREVERPRODUCTCHD
 
Im having difficulty with the directives i figured out a duplicatio.pdf
Im having difficulty with the directives i figured out a duplicatio.pdfIm having difficulty with the directives i figured out a duplicatio.pdf
Im having difficulty with the directives i figured out a duplicatio.pdfmaheshkumar12354
 
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
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdffantoosh1
 
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdfC++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdffeelinggift
 

Similar to Change the driver file (the main .cpp) so that it asks the user to e.pdf (20)

C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
 
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
 #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
 
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdfAnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptx
 
Ll.pptx
Ll.pptxLl.pptx
Ll.pptx
 
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
 
GIVEN CODE template -typename T- class DList { private- struct Node {.docx
GIVEN CODE template -typename T- class DList { private- struct Node {.docxGIVEN CODE template -typename T- class DList { private- struct Node {.docx
GIVEN CODE template -typename T- class DList { private- struct Node {.docx
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
 
include ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfinclude ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdf
 
DS - Application of List
DS - Application of ListDS - Application of List
DS - Application of List
 
CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1
 
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
 
I have to write a polynomial class linked list program and i do not .pdf
I have to write a polynomial class linked list program and i do not .pdfI have to write a polynomial class linked list program and i do not .pdf
I have to write a polynomial class linked list program and i do not .pdf
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfimplement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
 
Im having difficulty with the directives i figured out a duplicatio.pdf
Im having difficulty with the directives i figured out a duplicatio.pdfIm having difficulty with the directives i figured out a duplicatio.pdf
Im having difficulty with the directives i figured out a duplicatio.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
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
 
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdfC++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
 

More from fatoryoutlets

Write an informal paper that is exactly 3 pages long not counting th.pdf
Write an informal paper that is exactly 3 pages long not counting th.pdfWrite an informal paper that is exactly 3 pages long not counting th.pdf
Write an informal paper that is exactly 3 pages long not counting th.pdffatoryoutlets
 
Write a C program to find factorial of an integer n, where the user .pdf
Write a C program to find factorial of an integer n, where the user .pdfWrite a C program to find factorial of an integer n, where the user .pdf
Write a C program to find factorial of an integer n, where the user .pdffatoryoutlets
 
When was the black body mutation in drosophila melanogaster discover.pdf
When was the black body mutation in drosophila melanogaster discover.pdfWhen was the black body mutation in drosophila melanogaster discover.pdf
When was the black body mutation in drosophila melanogaster discover.pdffatoryoutlets
 
What is it that consumer researchers try to find among varying cultu.pdf
What is it that consumer researchers try to find among varying cultu.pdfWhat is it that consumer researchers try to find among varying cultu.pdf
What is it that consumer researchers try to find among varying cultu.pdffatoryoutlets
 
What are pros and cons of Symantec endpoint security softwareSo.pdf
What are pros and cons of Symantec endpoint security softwareSo.pdfWhat are pros and cons of Symantec endpoint security softwareSo.pdf
What are pros and cons of Symantec endpoint security softwareSo.pdffatoryoutlets
 
All of the following describe the International Accounting Standard .pdf
All of the following describe the International Accounting Standard .pdfAll of the following describe the International Accounting Standard .pdf
All of the following describe the International Accounting Standard .pdffatoryoutlets
 
The right and left sternocleidomastoid muscles of humans originate o.pdf
The right and left sternocleidomastoid muscles of humans originate o.pdfThe right and left sternocleidomastoid muscles of humans originate o.pdf
The right and left sternocleidomastoid muscles of humans originate o.pdffatoryoutlets
 
The code in image3.cpp has the error as shown above, could you help .pdf
The code in image3.cpp has the error as shown above, could you help .pdfThe code in image3.cpp has the error as shown above, could you help .pdf
The code in image3.cpp has the error as shown above, could you help .pdffatoryoutlets
 
the ability of the cardiac muscle cells to fire on their own is .pdf
the ability of the cardiac muscle cells to fire on their own is .pdfthe ability of the cardiac muscle cells to fire on their own is .pdf
the ability of the cardiac muscle cells to fire on their own is .pdffatoryoutlets
 
Template LinkedList;I am using templates to make some linkedLists.pdf
Template LinkedList;I am using templates to make some linkedLists.pdfTemplate LinkedList;I am using templates to make some linkedLists.pdf
Template LinkedList;I am using templates to make some linkedLists.pdffatoryoutlets
 
Surface water entering the North Atlantic may have a temperature of .pdf
Surface water entering the North Atlantic may have a temperature of .pdfSurface water entering the North Atlantic may have a temperature of .pdf
Surface water entering the North Atlantic may have a temperature of .pdffatoryoutlets
 
Suppose the rate of plant growth on Isle Royale supported an equilib.pdf
Suppose the rate of plant growth on Isle Royale supported an equilib.pdfSuppose the rate of plant growth on Isle Royale supported an equilib.pdf
Suppose the rate of plant growth on Isle Royale supported an equilib.pdffatoryoutlets
 
Q1. public void operationZ() throws StackUnderflowException {   .pdf
Q1. public void operationZ() throws StackUnderflowException {   .pdfQ1. public void operationZ() throws StackUnderflowException {   .pdf
Q1. public void operationZ() throws StackUnderflowException {   .pdffatoryoutlets
 
Print Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdf
Print Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdfPrint Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdf
Print Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdffatoryoutlets
 
Part A 1. Solid product forms during the addition of the bleach solu.pdf
Part A 1. Solid product forms during the addition of the bleach solu.pdfPart A 1. Solid product forms during the addition of the bleach solu.pdf
Part A 1. Solid product forms during the addition of the bleach solu.pdffatoryoutlets
 
Only 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdf
Only 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdfOnly 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdf
Only 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdffatoryoutlets
 
Note Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdfNote Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdffatoryoutlets
 
Negotiations are not usually faster in Deal focused cultures than re.pdf
Negotiations are not usually faster in Deal focused cultures than re.pdfNegotiations are not usually faster in Deal focused cultures than re.pdf
Negotiations are not usually faster in Deal focused cultures than re.pdffatoryoutlets
 
9. The tort of assault and the tort of battery A) can occur independe.pdf
9. The tort of assault and the tort of battery A) can occur independe.pdf9. The tort of assault and the tort of battery A) can occur independe.pdf
9. The tort of assault and the tort of battery A) can occur independe.pdffatoryoutlets
 
Jj_numjnamecityj1SorterParisj2PunchRomej3Reade.pdf
Jj_numjnamecityj1SorterParisj2PunchRomej3Reade.pdfJj_numjnamecityj1SorterParisj2PunchRomej3Reade.pdf
Jj_numjnamecityj1SorterParisj2PunchRomej3Reade.pdffatoryoutlets
 

More from fatoryoutlets (20)

Write an informal paper that is exactly 3 pages long not counting th.pdf
Write an informal paper that is exactly 3 pages long not counting th.pdfWrite an informal paper that is exactly 3 pages long not counting th.pdf
Write an informal paper that is exactly 3 pages long not counting th.pdf
 
Write a C program to find factorial of an integer n, where the user .pdf
Write a C program to find factorial of an integer n, where the user .pdfWrite a C program to find factorial of an integer n, where the user .pdf
Write a C program to find factorial of an integer n, where the user .pdf
 
When was the black body mutation in drosophila melanogaster discover.pdf
When was the black body mutation in drosophila melanogaster discover.pdfWhen was the black body mutation in drosophila melanogaster discover.pdf
When was the black body mutation in drosophila melanogaster discover.pdf
 
What is it that consumer researchers try to find among varying cultu.pdf
What is it that consumer researchers try to find among varying cultu.pdfWhat is it that consumer researchers try to find among varying cultu.pdf
What is it that consumer researchers try to find among varying cultu.pdf
 
What are pros and cons of Symantec endpoint security softwareSo.pdf
What are pros and cons of Symantec endpoint security softwareSo.pdfWhat are pros and cons of Symantec endpoint security softwareSo.pdf
What are pros and cons of Symantec endpoint security softwareSo.pdf
 
All of the following describe the International Accounting Standard .pdf
All of the following describe the International Accounting Standard .pdfAll of the following describe the International Accounting Standard .pdf
All of the following describe the International Accounting Standard .pdf
 
The right and left sternocleidomastoid muscles of humans originate o.pdf
The right and left sternocleidomastoid muscles of humans originate o.pdfThe right and left sternocleidomastoid muscles of humans originate o.pdf
The right and left sternocleidomastoid muscles of humans originate o.pdf
 
The code in image3.cpp has the error as shown above, could you help .pdf
The code in image3.cpp has the error as shown above, could you help .pdfThe code in image3.cpp has the error as shown above, could you help .pdf
The code in image3.cpp has the error as shown above, could you help .pdf
 
the ability of the cardiac muscle cells to fire on their own is .pdf
the ability of the cardiac muscle cells to fire on their own is .pdfthe ability of the cardiac muscle cells to fire on their own is .pdf
the ability of the cardiac muscle cells to fire on their own is .pdf
 
Template LinkedList;I am using templates to make some linkedLists.pdf
Template LinkedList;I am using templates to make some linkedLists.pdfTemplate LinkedList;I am using templates to make some linkedLists.pdf
Template LinkedList;I am using templates to make some linkedLists.pdf
 
Surface water entering the North Atlantic may have a temperature of .pdf
Surface water entering the North Atlantic may have a temperature of .pdfSurface water entering the North Atlantic may have a temperature of .pdf
Surface water entering the North Atlantic may have a temperature of .pdf
 
Suppose the rate of plant growth on Isle Royale supported an equilib.pdf
Suppose the rate of plant growth on Isle Royale supported an equilib.pdfSuppose the rate of plant growth on Isle Royale supported an equilib.pdf
Suppose the rate of plant growth on Isle Royale supported an equilib.pdf
 
Q1. public void operationZ() throws StackUnderflowException {   .pdf
Q1. public void operationZ() throws StackUnderflowException {   .pdfQ1. public void operationZ() throws StackUnderflowException {   .pdf
Q1. public void operationZ() throws StackUnderflowException {   .pdf
 
Print Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdf
Print Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdfPrint Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdf
Print Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdf
 
Part A 1. Solid product forms during the addition of the bleach solu.pdf
Part A 1. Solid product forms during the addition of the bleach solu.pdfPart A 1. Solid product forms during the addition of the bleach solu.pdf
Part A 1. Solid product forms during the addition of the bleach solu.pdf
 
Only 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdf
Only 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdfOnly 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdf
Only 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdf
 
Note Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdfNote Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdf
 
Negotiations are not usually faster in Deal focused cultures than re.pdf
Negotiations are not usually faster in Deal focused cultures than re.pdfNegotiations are not usually faster in Deal focused cultures than re.pdf
Negotiations are not usually faster in Deal focused cultures than re.pdf
 
9. The tort of assault and the tort of battery A) can occur independe.pdf
9. The tort of assault and the tort of battery A) can occur independe.pdf9. The tort of assault and the tort of battery A) can occur independe.pdf
9. The tort of assault and the tort of battery A) can occur independe.pdf
 
Jj_numjnamecityj1SorterParisj2PunchRomej3Reade.pdf
Jj_numjnamecityj1SorterParisj2PunchRomej3Reade.pdfJj_numjnamecityj1SorterParisj2PunchRomej3Reade.pdf
Jj_numjnamecityj1SorterParisj2PunchRomej3Reade.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
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
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
 
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
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
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
 
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
 
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
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

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
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
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
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
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
 
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
 
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
 
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)
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

Change the driver file (the main .cpp) so that it asks the user to e.pdf

  • 1. Change the driver file (the main .cpp) so that it asks the user to enter the values, then prints them, reverses them, and prints them again. DO NOT USE THE revprint2 function that is in the code! LinkListImp.cpp //----- List.cpp ----- #include using namespace std; #include "linkedlist.h" //-- Definition of the class constructor List::List() : first(0), mySize(0) { } //-- Definition of the copy constructor List::List(const List & origList) { mySize = origList.mySize; first = 0; if (mySize == 0) return; List::NodePointer origPtr, lastPtr; first = new Node(origList.first->data); // copy first node lastPtr = first; origPtr = origList.first->next; while (origPtr != 0) { lastPtr->next = new Node(origPtr->data); origPtr = origPtr->next; lastPtr = lastPtr->next; } } //-- Definition of the destructor inline List::~List() { List::NodePointer prev = first, ptr; while (prev != 0) {
  • 2. ptr = prev->next; delete prev; prev = ptr; } } // Definition of empty() bool List::empty() { return mySize == 0; } //-- Definition of the assignment operator const List & List::operator=(const List & rightSide) { mySize = rightSide.mySize; first = 0; if (mySize == 0) return *this; if (this != &rightSide) { this->~List(); List::NodePointer origPtr, lastPtr; first = new Node(rightSide.first->data); // copy first node lastPtr = first; origPtr = rightSide.first->next; while (origPtr != 0) { lastPtr->next = new Node(origPtr->data); origPtr = origPtr->next; lastPtr = lastPtr->next; } } return *this; } //-- Definition of insert() void List::insert(ElementType dataVal, int index) { if (index < 0 || index > mySize)
  • 3. { cerr << "Illegal location to insert -- " << index << endl; return; } mySize++; List::NodePointer newPtr = new Node(dataVal), predPtr = first; if (index == 0) { newPtr->next = first; first = newPtr; } else { for (int i = 1; i < index; i++) predPtr = predPtr->next; newPtr->next = predPtr->next; predPtr->next = newPtr; } } //-- Definition of erase() void List::erase(int index) { if (index < 0 || index >= mySize) { cerr << "Illegal location to delete -- " << index << endl; return; } mySize--; List::NodePointer ptr, predPtr = first; if (index == 0) { ptr = first; first = ptr->next; delete ptr;
  • 4. } else { for (int i = 1; i < index; i++) predPtr = predPtr->next; ptr = predPtr->next; predPtr->next = ptr->next; delete ptr; } } //-- Definition of search() int List::search(ElementType dataVal) { int loc; List::NodePointer tempP = first; for (loc = 0; loc < mySize; loc++) if (tempP->data == dataVal) return loc; else tempP = tempP->next; return -1; } //-- Definition of display() void List::display(ostream & out) const { NodePointer ptr = first; while (ptr != 0) { out << ptr->data << " "; ptr = ptr->next; } } void List::revPrint(ostream & out) { reverse();
  • 5. display(out); reverse(); } void List::revPrint2(ostream &out, NodePointer ptr) { out << "Inside revPrint2 "; static List::NodePointer point = first; out << point->data << endl; if (point != NULL) { out << "Inside if statement "; revPrint2(out, point->next); out << point->data; } } //-- Definition of the output operator ostream & operator<<(ostream & out, const List & aList) { aList.display(out); return out; } //-- Definition of nodeCount() int List::nodeCount() { // or simply, { return mySize; } int count = 0; List::NodePointer ptr = first; while (ptr != 0) { count++; ptr = ptr->next; } return count; } //-- Definition of reverse() void List::reverse() {
  • 6. } //-- Definition of ascendingOrder() bool List::ascendingOrder() { if (mySize <= 1) //empty or one element list return true; //else NodePointer prevP = first, tempP = first->next; while (tempP != 0 && prevP->data <= tempP->data) { prevP = tempP; tempP = tempP->next; } if (tempP != 0) return false; // else return true; } linkedlist.cpp #include using namespace std; #include "linkedlist.h" int main() { List mylist; for (int i = 0; i < 6; i++) mylist.insert(i * 2, i); mylist.display(cout); cout << endl; mylist.revPrint(cout); cout << endl; cout << mylist;
  • 7. } linkedlist.h //----- List.h ----- #ifndef LINKEDLIST #define LINKEDLIST #include using namespace std; typedef int ElementType; class List { private: class Node { public: ElementType data; Node * next; Node() : next(0) { } Node(ElementType dataValue) : data(dataValue), next(0) { } }; //--- end of Node class typedef Node * NodePointer; public: //------ List OPERATIONS List(); List(const List & origList); ~List(); const List & operator=(const List & rightSide); bool List::empty(); void insert(ElementType dataVal, int index); void erase(int index); int search(ElementType dataVal);
  • 8. void display(ostream & out) const; void revPrint(ostream & out); void revPrint2(ostream &out, NodePointer ptr = NULL); int nodeCount(); void reverse(); bool ascendingOrder(); private: //------ DATA MEMBERS NodePointer first ; int mySize; }; //--- end of List class ostream & operator<<(ostream & out, const List & aList); //istream & operator>>(istream & in, List & aList); #endif Solution ////----- List.cpp ----- //added reverse functionality #include using namespace std; #include "linkedlist.h" //-- Definition of the class constructor List::List() : first(0), mySize(0) { } //-- Definition of the copy constructor List::List(const List & origList) { mySize = origList.mySize; first = 0; if (mySize == 0) return; List::NodePointer origPtr, lastPtr; first = new Node(origList.first->data); // copy first node lastPtr = first; origPtr = origList.first->next;
  • 9. while (origPtr != 0) { lastPtr->next = new Node(origPtr->data); origPtr = origPtr->next; lastPtr = lastPtr->next; } } //-- Definition of the destructor inline List::~List() { List::NodePointer prev = first, ptr; while (prev != 0) { ptr = prev->next; delete prev; prev = ptr; } } // Definition of empty() bool List::empty() { return mySize == 0; } //-- Definition of the assignment operator const List & List::operator=(const List & rightSide) { mySize = rightSide.mySize; first = 0; if (mySize == 0) return *this; if (this != &rightSide) { this->~List(); List::NodePointer origPtr, lastPtr; first = new Node(rightSide.first->data); // copy first node lastPtr = first;
  • 10. origPtr = rightSide.first->next; while (origPtr != 0) { lastPtr->next = new Node(origPtr->data); origPtr = origPtr->next; lastPtr = lastPtr->next; } } return *this; } //-- Definition of insert() void List::insert(ElementType dataVal, int index) { if (index < 0 || index > mySize) { cerr << "Illegal location to insert -- " << index << endl; return; } mySize++; List::NodePointer newPtr = new Node(dataVal), predPtr = first; if (index == 0) { newPtr->next = first; first = newPtr; } else { for (int i = 1; i < index; i++) predPtr = predPtr->next; newPtr->next = predPtr->next; predPtr->next = newPtr; } } //-- Definition of erase() void List::erase(int index)
  • 11. { if (index < 0 || index >= mySize) { cerr << "Illegal location to delete -- " << index << endl; return; } mySize--; List::NodePointer ptr, predPtr = first; if (index == 0) { ptr = first; first = ptr->next; delete ptr; } else { for (int i = 1; i < index; i++) predPtr = predPtr->next; ptr = predPtr->next; predPtr->next = ptr->next; delete ptr; } } //-- Definition of search() int List::search(ElementType dataVal) { int loc; List::NodePointer tempP = first; for (loc = 0; loc < mySize; loc++) if (tempP->data == dataVal) return loc; else tempP = tempP->next; return -1; }
  • 12. //-- Definition of display() void List::display(ostream & out) const { NodePointer ptr = first; while (ptr != 0) { out << ptr->data << " "; ptr = ptr->next; } } void List::revPrint(ostream & out) { reverse(); display(out); reverse(); } void List::revPrint2(ostream &out, NodePointer ptr) { out << "Inside revPrint2 "; static List::NodePointer point = first; out << point->data << endl; if (point != NULL) { out << "Inside if statement "; revPrint2(out, point->next); out << point->data; } } //-- Definition of the output operator ostream & operator<<(ostream & out, const List & aList) { aList.display(out); return out; } //-- Definition of nodeCount() int List::nodeCount()
  • 13. { // or simply, { return mySize; } int count = 0; List::NodePointer ptr = first; while (ptr != 0) { count++; ptr = ptr->next; } return count; } //-- Definition of reverse() //added by chegg EA void List::reverse() { static List::NodePointer current,next,prev; prev = NULL; current = first; while (current != NULL) { next = current->next; current->next = prev; prev = current; current = next; } first= prev; } //-- Definition of ascendingOrder() bool List::ascendingOrder() { if (mySize <= 1) //empty or one element list return true; //else NodePointer prevP = first, tempP = first->next;
  • 14. while (tempP != 0 && prevP->data <= tempP->data) { prevP = tempP; tempP = tempP->next; } if (tempP != 0) return false; // else return true; } ------------------------------------------------------------------------ // List.h this file unchanged --------------------------------------------------------------- //main.cpp #include using namespace std; #include "linkedlist.h" int main() { List mylist; int num; for (int i = 0; i < 6; i++) { //mylist.insert(i * 2, i); //added by chegg EA,ask for user input cin >> num; mylist.insert(num, i); } cout << "mylist: "; mylist.display(cout); cout << endl; //mylist.revPrint(cout); //added by chegg EA,reverse the list mylist.reverse(); //added by chegg EA, print the reversed list
  • 15. cout << endl; cout << "After reversing the list: "<