using namespace std; //The constructor reads in all the integers and stores them
ID: 3624680 • Letter: U
Question
using namespace std;
//The constructor reads in all the integers and stores them in the
//object of type dataStructure
dataStructure::dataStructure()
{
startPtr = NULL;
node* ptr = startPtr;
int data;
cin >> data;
ptr = startPtr;
while(cin)
{
if(ptr == NULL)
{
startPtr = new node;
startPtr->data = data;
startPtr->next = NULL;
ptr = startPtr;
}
else
{
ptr->next = new node;
ptr = ptr->next;
ptr->data = data;
ptr->next = NULL;
}
cin >> data;
}
}
//displayNodes is the helper function that the client calls.
//It calls the recursive function displayAll which will
//display the nodes in backward.
//It passes the startPtr as the starting point for displaying.
void dataStructure::displayNodes()
{
int n = 0;
displayAll(startPtr);
return;
}
// put code for the recursive function displayAll(node* ptr) that will
// display the nodes within the dataStructure in backward.
// To display backward, each of the should be visited before the data value is displayed.
CODE HERE after reading the comments above:
Explanation / Answer
void dataStructure ::displayAll(node* ptr)
{
while(ptr!=NULL)
{
cout<<ptr->data<<"-->"
ptr=ptr->next;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.