#if 1 #include #include using namespace std; struct Node { string data; Node *next; }; Node* createSillyList(); int main() { Node* list = 0; list = createSillyList(); cout << "node 0 is: " << list << endl; cout << "word 0: " << list->data << endl; cout << "node 1: " << list->next << endl; cout << "word 1: " << list->next->data << endl; cout << "node 2: " << list->next->next << endl; cout << "word 2: " << list->next->next->data << endl; cout << "insert thing below" << endl; // Make a new node Node *temp; temp = new Node; // Make new node point to first node in old list temp->next = list; // Change list to point to the new node list = temp; // Fill in the data list->data = "the"; cout << "take 2" << endl; Node *ptr; ptr = list; cout << "node is: " << ptr << endl; cout << "word is " << ptr->data << endl; ptr = ptr->next; cout << "node is: " << ptr << endl; cout << "word is " << ptr->data << endl; ptr = ptr->next; cout << "node is: " << ptr << endl; cout << "word is " << ptr->data << endl; ptr = ptr->next; cout << "node is: " << ptr << endl; cout << "word is " << ptr->data << endl; return 0; } // Make a new node to hold given string and add to front of list void my_addToFront(Node *&list, string data) { Node *temp = new Node; temp->data = data; temp->next = list; list = temp; } // Returns a simple list of nodes Node *createSillyList() { Node *list; my_addToFront(list, "hat"); my_addToFront(list, "the"); my_addToFront(list, "in"); my_addToFront(list, "cat"); return list; } #endif