Answered step by step
Verified Expert Solution
Question
1 Approved Answer
can you check and correct the following coding ? #include #include string #include 11 A node in the binary search tree 8 struct Node 1
can you check and correct the following coding ? \#include \#include string \#include 11 A node in the binary search tree 8 struct Node 1 9 std::string word; std: :vector positions; Node : left; Node* right; (10) 1/ Inserts a new word into the tree void insert(Node*\& root, const std: :string\& word, int position) \& 17 if (root = nullptr) root = new Node\{word, (position\}, nullptr, nullptr); ]) else if (word word) {. insert (root->left, word, position); \} else if (word > root->word) \{ insert (root-rright, word, position): else \{ 1/ word already exists in tree, just add position to list root->positions.push back(position); /I Finds the positions of a given word in the tree std: : vector find(Node* root, const std: :stringe word) (f if (root = nullptr) 1/ Word not found return \{\}: else if (word left, word); 3 else if (word > root->word) return find (root->right, word); else \{ // Makes the intersection of two lists of positions 47 std: back inserter(result)); 48 return result; 493 51 // splits a line of text into individual words
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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