1. Engineering
  2. Computer Science
  3. you need to fix the following code which is in...

Question: you need to fix the following code which is in...

Question details

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<string> split(const string& s, char delimiter) {
vector<string> 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)
}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution