Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can you correct the coding for c++? // word not found J else ift (word word) (return) search(root->left, word); lelse if 1 (word> root->ward) {

can you correct the coding for c++? image text in transcribed
image text in transcribed
image text in transcribed
// word not found J else ift (word word) (return) search(root->left, word); lelse if 1 (word> root->ward) \{ return search(root- >right, word); telse (// word a root-swordreturn root-spositions; ) H// Recursive function to find the intersection of two listsstd:ivectoreint> std:ivectoreint> result; for (auto ilisti) } if (stdi,find(list2, begin[), list2,end[l, i) l= list2,end()) f result.push back(i); ! return result); // function to search for a phrase in the treestdizvectorcints search phrase (Node root, const std:ivectorestd:string > \& phrase) ( std::vectorcint> positions = search(root, phrase[e]l; for ( int i=1; phrase, size (7;++i)1 positions = intersect (positions, search(root, phrase[1])): return positions]: int main() f Node root = nullptr; // Insert some words and positions into the tree insert(root, "hello", 1); insert(root, "world", 2); insert (root, "hello", 3): insert(root, "foo", 4): insert(root, "bar", 5): insert(root, "hello;, 6): insert(root, "foo", 7), // Search for a word in the treestdirvectorsint> positions search (root, "hello"); include Hinclude svectors struct Nodel int key; struct Node *left, "right; // Create a node struct Node "newNode(int item) struct Node *temp = (struct Node *)malloc(sizeofistruct Node ) ); temp->key item; temp->left = temp->right = NULL; return temp; J structNode (stdistring word; std:uvectorsint> positions; Node" Node left;Node right)] I/ Recursive function to insert a word and its position into the treevoidinsert (Node \& root, stdisstring word, int position) \{ if (Iroot) root = new Node(word, (position), nullptr, nullptr): leise f (word word) insert(root->left, word, position); Jelse iff (word root->word) insert(root-sright, word, position): telse iff // word anoot->word root->positions. push back { position );} // Recursive function to search for a word in the treestd:ivector cint search (Node* root, std: :string word) (If (lroot) return \&: /// Recursive function to find the intersection of two listsstd:vectorsint> intersect/const std:ivector\& list 1 , const std:ivector\& list2) \& std: vector result; for (auto i listi) \{ if (std:find(list2.begin(), list2,end(), i) != list2.end()) 1 result,push_back(i); ) return result\}; // Function to search for a phrase in the treestd:vectorsint > search phrase (Node root, const std::vector>& phrase) fstd;:vector positions = search(root, phrase[e]); for ( int i=1; phrase.size ( ) ++i ) \{ positions = intersect (positions, search(root, phrase[1])); return positions]; int main ()f Node root = nullptr; // Insert some words and positions into the tree insert(root, "heilo", 1); insert(root, "world", 2); insert (root, "hello", 3); insert(root, "foo", 4); insert(root, "bar", 5); insert(root, "hello", 6); insert(root, "foo", 7); // Search for a word in the treestd:ivector positions search (root, "hello"); std: cout "Positions of 'hello': "; for (auto i positions) \{ std:icout i" "; \}

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

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

Students also viewed these Databases questions

Question

What does time value of money mean? (LO 3)

Answered: 1 week ago

Question

LO 12-3 Outline the objectives of labor unions.

Answered: 1 week ago

Question

What attracts you about this role?

Answered: 1 week ago

Question

How many states in India?

Answered: 1 week ago

Question

HOW IS MARKETING CHANGING WITH ARTIFITIAL INTELIGENCE

Answered: 1 week ago

Question

Does it use a maximum of two typefaces or fonts?

Answered: 1 week ago