** Whenever I try to display the contents of prev which is the node pointing to the beginning of the list the values are not displayed.**
#include <iostream>
using namespace std;
struct NodeType{
int value;
struct NodeType* next;
};
class List{
private:
typedef struct NodeType* NodePtr;
NodePtr prev;
public:
List();
void addToList(void);
void insertNode(int x);
};
int main() {
List();
List addNode;
List viewList;
addNode.addToList();
return 0;
}
List::List() {
prev = NULL;
}
void List:: addToList() {
int val;
List toAdd;
NodePtr displayList;
while(1) {
cout << "Enter a value to be added to the list (0 to termiante):";
cin >> val;
if(val == 0)
break;
toAdd.insertNode(val);
}
for(displayList = prev; displayList != NULL; displayList=displayList->next) {
cout << displayList -> value;
}
void List::insertNode(int val) {
NodePtr head;
head = new NodeType;
head->value = val;
head->next = prev;
prev = head;
}
}