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
// 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started