Пример #1
0
//Recursively Search for data in the Tree
bool BinaryTree::rSearch(string s, TreeNode*& that) {

	//Base Cases
	if(that == NULL) 	{ return false; }
	if(s == that->data)	{ return true;  }

	//Alternative Cases
	if(s <= that->data) { return rSearch(s, that->left); }
	if(s >  that->data) { return rSearch(s, that->rght); }

	cout << "Recursive Search has Failed" << endl;
	return false;
}
Пример #2
0
    vector<int> searchRange(int A[], int n, int target) {
        vector<int> res;
        if(n <= 0)
            return res;
 
        int leftIndex = lSearch(A, n, target);
        int rightIndex = rSearch(A, n, target);
         
        res.push_back(leftIndex);
        res.push_back(rightIndex);
        return res;
    }
Пример #3
0
//Search for data in the Tree
bool BinaryTree::search(string s) 	{ return rSearch(s, root); }