linked_list.cpp - #include <iostream>#include <string> using namespace std struct Node cfw int key Node next void insert Node head int key cfw Node temp

linked_list.cpp - #include <iostream>#include <string>...

This preview shows page 1 - 2 out of 2 pages.

#include <iostream> #include <string> using namespace std; struct Node { int key; Node* next; }; void insert( Node*& head, int key) { Node * temp; temp = new Node; temp->key = key; temp->next = head; head = temp; } void print( Node* head ) { Node* temp = head; cout << "["; while( temp != NULL ) { cout << temp->key; if( temp->next != NULL ) cout << ", "; temp = temp->next; } cout << "]" << endl; } // This function deletes the last element in the linked list. // Pre-condition: The head of a linked list is provided. // Post-condition: The last element of that linked list has been removed. void delete_last_element( Node*& head ) { //please write your own code here } // This function inserts a key after a node with a given key. // If there is no node with the given key, no action. // Pre-condition: The head of a linked list, // a key to indicate where to insert, // and a new key to insert are provided. // Post-condition: If a node with key is found, the linked list // contains a new node (newKey) after that node. void insert_after( Node* head, int key, int newKey ) { //please write your own code here } // This function merges two linked lists.
Image of page 1
Image of page 2

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture