Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!