Please help me out with this, I\'ve tried to get it to work, and it compiles but
ID: 3545384 • Letter: P
Question
Please help me out with this, I've tried to get it to work, and it compiles but wont execute and give the right answer to me...
The part that is needed is at the very end, thank you!! If you want I can provide my part of the code, but I think that it is wrong..
#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.
*************************
Explanation / Answer
void dataStructure ::displayAll(node* ptr)
{
while(ptr!=NULL)
{
cout<<ptr->data<<"-->"
ptr=ptr->next;
}