Binary Searcht Ree Code Example


Example: binary tree search

/* This is just the seaching function you need to write the required code. 	Thank you. */  void searchNode(Node *root, int data) {     if(root == NULL)     {         cout << "Tree is empty\n";         return;     }      queue<Node*> q;     q.push(root);      while(!q.empty())     {         Node *temp = q.front();         q.pop();          if(temp->data == data)         {             cout << "Node found\n";             return;         }          if(temp->left != NULL)             q.push(temp->left);         if(temp->right != NULL)             q.push(temp->right);     }      cout << "Node not found\n"; }

Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?