Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You need to fix the following code, which is in C++. The program must accept a string, obtained using getline. The inputted string must be

You need to fix the following code, which is in C++. The program must accept a string, obtained using getline. The inputted string must be passed to the split() function. The split() function is suppose to split the string up into it's component word and-or characters and return them as tokens. The tokens are then sent to the insert() function to store the tokens in a linked list. The tokens stored in the linked list will then formatted and then displayed. Your code must compile and run. Please comment any changes/all your code.

// driver function int main() { string str; cout<<">"; getline(cin, str); // call the split() function, passing in the string as an argument // call the insert() function, passing the tokens returned from the split() function }

vector split(const string& s, char delimiter) { vector tokens; string token; istringstream tokenStream(s); while (getline(tokenStream, token, delimiter)) { tokens.push_back(); } return tokens; }

// inserts the tokens into the beginning of the linked list void insert() { struct Node* new_node = (struct Node*) malloc(sizeof(struct Node)); // create a new node new_node->data = ; // insert the token in the data field of the new node new_node->next = head; // new node points to the head head = new_node; // head is the new node (i.e. linked list starts here) }

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

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions