Hi,
I have already spent some time trying to make work the following code . there is no error message , but an exception instead. the problem seems to come from the fonctions of the class Node and perhaps of the pointer Next which is not well defined.
Thanks for any advice.Code:#include<iostream> using namespace std; class UseNodes { private: class Node { public: Node() { Data = 1; Next = 0; } Node(int a):Data(a) {} ~Node(){}; Node* GetNext()const{ return Next;} void SetNext( Node* A){ Next = A;} int GetData()const{ return Data;} void setData(int a) { Data = a;} private: Node* Next; int Data; }; Node* Head; Node* Tail; public: UseNodes(){Head = 0; Tail = 0; } ~UseNodes(){}; void AddNode(int a) { Node* Temp = new Node(a); if(Head==0) { Head = Temp; Tail = Temp; } else { Node* Current = new Node(); Current = Head; while(Current) { Current = Current->GetNext(); } Current->SetNext(Temp); Tail = Temp; } } void Print()const { int a = 2; Node* Temp = new Node(a); if(Head==0) cout << " Empty list.\n " ; else { Temp = Head; cout << Head->GetData() << endl; while(Temp!=Tail->GetNext()) { cout << Temp->GetData() << endl; Temp = Temp->GetNext() ; } } } }; int main() { UseNodes A; A.AddNode(29); A.AddNode(7777); A.Print(); getchar(); }



LinkBack URL
About LinkBacks


