Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

Is short-selling good for the stock markets?

Answered: 1 week ago

Question

What is the formula for market capitalization using excel?

Answered: 1 week ago

Question

7. Identify six intercultural communication dialectics.

Answered: 1 week ago