//This is the implementation file for the methods in the dataStructure //class.
ID: 3556176 • Letter: #
Question
//This is the implementation file for the methods in the dataStructure
//class.
#include "2170_recursiveLista.h"
#include <iostream>
#include <stdlib.h>
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.
// 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.
Explanation / Answer
TRY THIS
void displayAll(node* ptr) {
if(ptr==null)
return;
displayAll(ptr->next);
cout<<ptr->data<<endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.