#include using namespace std; struct node { int x; node *next; }; int main() { node *head; // the first node in the list node *current; // a way of keeping track of the nodes head = new node; // Sets it to actually point to something head->next = NULL; // there are no items in the list yet head->x = 12; current = head; // the current item points to the head (really first item) // lets add an item to the end of the list if ( current != NULL ) { while ( current->next != NULL) current = current->next; } current->next = new node; // Creates a node at the end of the list current = current->next; // Points to that node current->next = NULL; // Prevents it from going any further current->x = 24; // create another node if ( current != NULL ) { // go to the end of the list again while ( current->next != NULL) current = current->next; } current->next = new node; // Creates a node at the end of the list current = current->next; // Points to that node current->next = NULL; // Prevents it from going any further current->x = 36; // lets print the list current = head; if ( current != NULL ) { //Makes sure there is a place to start while ( current->next != NULL ) { cout<< current->x << endl; current = current->next; } cout<< current->x << endl; } // lets add an item behind the head current = head; current = new node; // create and current->next = head->next; head->next = current; current->x = head->x; // because the head node is storing a value head->x = 48; // the new node is the head node now cout <<"Now with one added to the start:" << endl << endl; current = head; if ( current != NULL ) { while ( current->next != NULL ) { cout<< current->x << endl; current = current->next; } cout<< current->x << endl; } getchar(); }