#include using namespace std; struct Node { int data; Node* next; }; void printList( Node* start ) { while ( start != NULL ) { //print current element cout << start -> data < next; } start = NULL; } //PreCondition: //start is an undetermined (even blank) sized linked list //nodeToAdd is already initialized //PostCondition: //Will return the start of a linked list with at least 1 element Node* addAtBack( Node* start, Node* nodeToAdd ) { //If list is empty if ( NULL == start ) { //make sure starts next pointer is null nodeToAdd -> next = NULL; //return nodeToAdd return nodeToAdd; } //If list is not empty else { //iterate down to last element Node* temp = start; while ( temp -> next != NULL ) { temp = temp -> next; //advance 1 node down list } //temp is now pointing to the last element in the list //set list->next pointer to point to temp temp -> next = nodeToAdd; return start; } } int main() { Node* head = NULL; //create holder for start of list head = new Node(); //allocate space for node, return ptr head -> data = 1; //dereference head, use dot op. and assign 1 head -> next = NULL; // printList ( head ); Node* temp = new Node(); // create a temp pointer temp -> data = 2; temp -> next = NULL; head = addAtBack( head, temp ); printList( head ); }