struct car{       
     string marque;         // -- brand 
     string model;          // -- model
     bool isRented;         // -- flag of whether the car is rented
     bool reCommissioned;   // -- flag of whether the car is reCommissioned (ready to be rented again)
     bool inService;        // -- flag of whether the car is in service.
     car * left;            // -- points at the left child
     car * right;           // -- points at the right child
};
// Search for CarToBeSearched in the tree recursively.
carBST::car* carBST::Search(car* CarToBeSearched, car* node) {
 // CarToBeSearched is found!
 if(CarToBeSearched->model.compare(node->model) == 0) {
  return node;
 // CarToBeSearched is smaller than current node.
 // continue searching in left subtree
 } else if (CarToBeSearched->model.compare(node->model) < 0) {
  if (node->left != NULL) {
   return Search(CarToBeSearched, node->left);
  }
 // CarToBeSearched is greater than current node.
 // continue searching in right subtree
 } else if (CarToBeSearched->model.compare(node->model) > 0) {
  if (node->right != NULL) {
   return Search(CarToBeSearched, node->right);
  }
 }
 //CarToBeSearched is not found in the tree.
 return NULL;
}
 
댓글 없음:
댓글 쓰기