// MyList.C // (c) Burton Rosenberg 1996 // Program to demonstrate linked lists. #include #include class Node { public: int item ; Node * next ; } ; class List { private: Node * anchor ; public: void init(void) ; void push(int i) ; void print(void) ; } ; void List:: init ( void ) { anchor = NULL ; } void List:: push( int i ) { Node * n = new Node ; n->item = i ; n->next = anchor ; anchor = n ; } void List:: print( void ) { Node * n = anchor ; while ( n != NULL ) { cout << n->item << endl ; n = n->next ; } } void main() { List myList ; myList.init() ; myList.print() ; myList.push(1) ; myList.push(2) ; myList.push(3) ; myList.print() ; }