Expand|Select|Wrap|Line Numbers
- #ifndef binarySearchTree_h
- #define binarySearchTree_h
- #include <string>
- #include <iostream>
- using namespace std;
- //Define the node
- struct treeNode
- //An object of type TreeNode
- {
- string data;
- struct node* left;
- struct node* right;
- treeNode(string str)
- //constructor: Make a node containing str.
- {
- data = str;
- left = NULL;
- right = NULL;
- }
- };
- //define the class
- class binarySearchTree
- {
- public:
- binarySearchTree();
- //constructor
- bool isEmpty() const;
- //
- bool treeContains(treeNode *root, string data);
- //return true if item is one of the items in the
- //binary sort tree to which root points. Return
- //false if not
- protected:
- treeNode *root;
- };
- #endif
Expand|Select|Wrap|Line Numbers
- #include "binarySearchTree.h"
- #include <string>
- #include <iostream>
- using namespace std;
- binarySearchTree::binarySearchTree() :root(NULL)
- {
- }
- bool binarySearchTree::isEmpty() const
- //return true if tree is empty
- {
- return (root == NULL);
- }
- bool binarySearchTree::treeContains(treeNode *root, string data)
- //return true if item is one of the items in the
- //binary sort tree to which root points. Return
- //false if not
- {
- if(root==NULL)
- //tree is empty
- {
- return false;
- }
- if(data==root->data)
- //item has been found
- {
- return true;
- }
- if(data < root->data)
- //item is in left subtree
- {
- return treeContains(root->left, data); //error
- }
- else
- //item is in right subtree
- {
- return treeContains(root->right, data); //error
- }
- } //end treeContains()
Compiling...
test.cpp
binarySearchTree.cpp
c:\program files\microsoft visual studio\myprojects\binaryaddressbook\binarysearchtr ee.cpp(41) : error C2664: 'treeContains' : cannot convert parameter 1 from 'struct node *' to 'struct treeNode *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\program files\microsoft visual studio\myprojects\binaryaddressbook\binarysearchtr ee.cpp(46) : error C2664: 'treeContains' : cannot convert parameter 1 from 'struct node *' to 'struct treeNode *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
binaryAddressBook.exe - 2 error(s), 0 warning(s)
Here is my test file:
Expand|Select|Wrap|Line Numbers
- #include "binarySearchTree.h"
- #include <iostream>
- using namespace std;
- int main()
- {
- treeNode *root; //pointer to the root noode in the tree
- root = NULL; //start with an empty tree
- return 0;
- }
please help so I can get this thing going?
thank you