>but im not sure how to do that
It would be easier to build the data part of a node in your client code and pass it to the binary tree class. That would involve something like this:
struct data {
char arriveCity[30];
char departCity[30];
int totalPassengers;
int passengers;
int flightNumber;
};
struct node {
data item;
node *left, *right;
}; Then the input function could be easily modified:
bool binaryTree::insert(dataNode*& tree, data item) {
if (tree == NULL) {
tree = new node;
tree -> left = NULL;
tree -> right = NULL;
tree -> item = item;
return true;
}
else if (item -> flightNumber == tree -> item -> flightNumber)
return false;
else if (item -> flightNumber <= tree -> item -> flightNumber)
return insert (tree -> left, item);
else
return insert (tree -> right, item);
} >i dont know if it would balance the tree
No, it won't. Balancing is much more complicated than that. I have several binary search tree tutorials on my website if you want to take a look at them.
Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401