Was trying to implement a simple linked list program using c++ with only insert and display operations.There was no problem during compile time...the result was absent
Compiler Used:
DEV C++ 4.9.9.2
Code:#include <iostream>#include <conio.h> #include <process.h> using namespace std; class NODE { friend class LINKEDLIST;//to make LINKEDLIST a friend of NODE //in order to access NODE //but NODE cant access LINKEDLIST private: int DATA; NODE *LINK; }; class LINKEDLIST { private: NODE *START; public: LINKEDLIST(){START=NULL;} LINKEDLIST &Insert(int x); void Display(); }; LINKEDLIST &LINKEDLIST::Insert(int x) { NODE *NEW= new NODE; NEW->DATA=x; NEW->LINK=START->LINK; START=NEW; return *this; } void LINKEDLIST::Display() { NODE *ptr=START; while(ptr!=NULL) { cout<<ptr->DATA<<" "<<endl; ptr=ptr->LINK; } } int main() { LINKEDLIST L; L.Insert(45); L.Insert(78); L.Insert(10); L.Insert(99); L.Insert(16); L.Display(); getch(); return 0; }