#include using namespace std; #define null 0 struct Node { int data; Node* next; }; void addToListRef( Node* &thelist, int number); Node* addToListVal( Node* thelist, int number); int main() { Node* list = new Node; (*list).data = 1; // These next 2 lines are equivilant list -> data = 1; list -> next = null; //list -> next = '\0'; addToListRef( list, 2 ); list = addToListVal( list, 3 ); addToListRef( list, 4 ); list = addToListVal( list, 5 ); for ( int i = 0; i < 5; i++ ) { cout << list -> data < next; } } void addToListRef( Node* &thelist, int number ) { Node* nodeToAdd = new Node; nodeToAdd -> data = number; nodeToAdd -> next = null; if ( thelist == null ) //list is empty { thelist = nodeToAdd; return; } else //list is not empty { Node* list = thelist; while ( list -> next != null ) { list = list -> next; } list -> next = nodeToAdd; } } Node* addToListVal( Node* thelist, int number ) { Node* nodeToAdd = new Node; nodeToAdd -> data = number; nodeToAdd -> next = null; if ( thelist == null ) { return nodeToAdd; } else { Node* list = thelist; while ( thelist -> next != null ) { thelist = thelist -> next; } thelist -> next = nodeToAdd; return list; } }