Question: lab22.cpp is given and text file is given lab22.cpp: #include #include using namespace std; struct node { int data; node *next; }; node* initializeList(node*, int);
lab22.cpp is given and text file is given
lab22.cpp:
#include #include using namespace std; struct node { int data; node *next; }; node* initializeList(node*, int); void showMenu(); void insertPos(node*, int, int); void deleteLast(node*, node*); void deleteAll(node*); int frequency(node*, int); void sort(node*); void printList(node*); bool isEmpty(node*); // Read and understand the main function. No coding is // required in main, but please write your functions to // conform to the function calls originating in main. int main() { int input; int val; int toSearch; ifstream inData; inData.open("input.txt"); node *head = NULL; while (inData >> val) head = initializeList(head, val); inData.close(); while (true) { showMenu(); cin >> input; switch (input) { case 1: if (!isEmpty(head)) { cout > val; cout > toSearch; insertPos(head, val, toSearch); } else cout > toSearch; cout data = val; newNode->next = NULL; if (current == NULL) { current = newNode; return current; } while (current->next != NULL) current = current->next; current->next = newNode; return head; } // The showMenu function is also complete. No coding is required here. void showMenu() { cout data. // Consider these temporary pointers for traversal. node *temp1 = new node; node *temp2 = new node; // And somewhere to hold the value to be swapped. int tempValue = 0; // TODO: Complete this sort function here using any sort // algorithm. // And don't forget to delete dynamically allocated nodes. delete temp1; delete temp2;
input.txt:
10 20 30 40 50 15 25 35 45 55
Question: linked list with its original values. Much of the structure is given for a menu-driven C++ program to implement and perform operations on a singly linked list. 1. Read and understand the given code 2. Understand each function's purpose. Take note of the parameter types and return types 3. Implement the following functions: a. bool isEmpty(node *current_head) b. void insertPos(node *current, int val, int toSearch) c. void printList node *current) d. void deleteLast(node *current, node *trailCurrent) e. void deleteAll(node *current) f. int frequency(node *current, int toSearch) g. void sort(node *head) Test your implementation. Ensure each menu choice works correctly. Handling invalid input is not required. 4. 5. Submit a single completed .cpp file on Blackboard