* POST: a new vector<int> containing the keys in the correct order has been returned. */ std::vector<int> to_vector(Node* head) {std::vector<int> result;for (Node* curr = head; curr != NULL; curr = curr->next){ result.push_back(curr->key); }return result; }/** * Delete the last Node in the linked_list* PRE: head is the first Node in a linked_list (if NULL, linked_list is empty) * POST: the last Node of the linked_list has been removed* POST: if the linked_list is now empty, head has been changed* POST: else head remains the first Node in the linked_list*/void delete_last_element(Node*& head){if (head != NULL) {if (head -> next == NULL) {
head = NULL;delete head;} else {delete_last_element(head->next);}}}/*** Removes an existing Node (with key=oldKey) from the linked_list. * PRE: head is the first node in a linked_list (if NULL, linked_list is empty) * PRE: oldKey is the value of the key in the Node to be removed * PRE: if no Node with key=oldKey exists, the linked_list has not changed * POST: if a Node with key=oldKey was found, then it was deleted* POST: other Nodes with key=oldKey might still be in the linked_list* POST: head is the new first Node of the linked_list, if updated*/ void remove(Node*& head, int oldKey) {if (head != NULL) {if (head->key == oldKey) {Node* n = head->next;