c++ - Retrieving objects in Binary Search Tree -


i want preface saying little new this, please bear me. our assignment have implement our own binary search tree. use bst create address book of objects of type extpersontype(which has varying members etc).

for part looks , works, life of me can't figure out these 3 functions. have display info of object searching tree last name, month, , status.

they similar functions won't belabor of them. if can point me in right direction 1 of them believe can figure out. in advance!

i have stripped alot of code hit high points. let me know if want me post more

binarysearchtree template<class t> class binarysearchtree { private:      node<t>* root;  public:     binarysearchtree() { root = null; }     void displayinfo(t value);     bool search(t value);  template <class t> bool binarysearchtree<t>::search(t value)  {     node<t>* tree = root;  while (tree) {     if (tree->value)     {         return true;     }     else if (tree->value > value)     {         tree = tree->left;     }     else     {         tree = tree->right;     } } return false; }  template <class t> void binarysearchtree<t>::displayinfo(t value) { node<t>* tree = root;  while (tree) {     if (tree->value)     {         cout << tree->value;//i have overloaded << here display objects (works btw)     }     else if (tree->value > value)     {         tree = tree->left;     }     else     {         tree = tree->right;     }     } } 

addressbook.cpp.

addressbook<extpersontype> addressbook; extpersontype person;  int main() {    //reads input file         person.setinfo(firstname, lastname,                               month, day, year,                               street, city, state, zipcode,                               phonenumber, status);          addressbook.insert(person);       } }  void optionthree()  //the crux of problem {  string lastname;  cout << "enter last name of person: ";  cin >> lastname;  addressbook.printinfoof(lastname); } 

addressbook.h

template <class elemtype> class addressbook : public binarysearchtree<elemtype> { public:  addressbook();  void printinfoof(string);  void printnameinthemonth(int);  void printnameswithstatus(string); };   // print - info of template <class elemtype> void addressbook<elemtype>::printinfoof(string lastname) {   if(person.getlastname() == (last))     binarysearchtree::displayinfo(person);   else     cout << "not found" << endl; } 

as can see have no idea i'm doing. thank once again!

error c2451: conditional expression of type 'extpersontype' illegal no user-defined-conversion operator available can perform conversion, >or operator cannot called documents\visual studio 2010\projects\programming4\binarysearchtree.h(234): >while compiling class template member function 'void >binarysearchtree::displayinfo(t)' [ t=extpersontype ]

in binarysearchtree::displayinfo method have following line:

else if (tree->value > value) 

this line doing greater-than comparison between 2 objects of type extpersontype, there no default operator> custom classes.

if haven't implemented like

bool operator>(const extpersontype & other) const { ... } 

in extpersontype class, that's problem.

don't forget, if implement operator>, should implement operator<, operator>=, , operator<=.

generally, 1 should consider operator> , operator<= related pair, , operator< , operator>= related pair, , implement 1 of each pair negation of other, e.g.:

bool operator>(const extpersontype & other) const {     return !(*this <= other); }  bool operator<=(const extpersontype & other) const {     // actual comparison here } 

implementing comparisons in fashion reduces chances of errors down road, if need change how 2 extpersontype objects relate each other.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -