//created by Dr. Ramsey //sample starter code for HW4 #include using namespace std; struct Node { int value; Node *next; }; void print(Node *); Node * add_to_front(Node *, int ); Node * add_to_end(Node *, int); //to be added Node * release_all(Node *); // to be added int main() { Node * head = NULL; char c = 'y'; int value; print(head); while(c == 'y') { cout << "Insert value: "; cin >> value; head = add_to_end(head,value); print(head); cout << "Continue? (y/n): "; cin >> c; } head = release_all(head); print(head); } //add a new node to the front of an existing linked list //the returned head is always the new node as it is always //at the front of the list Node *add_to_front(Node *head, int val) { Node *added_node = new Node; added_node->value = val; added_node->next = head; head = added_node; return head; } //print out the linked list or print empty if empty void print(Node *head) { if(head == NULL) { cout << "List is empty" << endl; //cout << (*head).value << endl; //DO NOT DEREFERENCE NULL or //seg fault return; // done handling the empty list } Node *current_pointer = head; //this pointer is going to describe where we are in the list while(current_pointer != NULL) { cout << current_pointer->value << " "; current_pointer = current_pointer->next; } cout << endl; }