Reputation: 1583
Should I always, use some data as a key value while dealing with the Binary Search trees? I'm asking this becasue I would need key at some point of time if I want to search an element in the tree. Is thre any other alternative?
For example, please consider the following code:
class Node {
int iData; // data used as key value
double fData; // other data
Node leftChild; // this node's left child
Node rightChild; // this node's right child
}
My Second Question:
Is there any way I can find elements in a Binary Tree as Binary Tree doesn't have any property just like Binary Search Tree where left node of parent must be less than the parent and right node must be greater.
Upvotes: 2
Views: 1059
Reputation: 41143
double fData
as the value you use to determine which node is bigger / smaller (if your requirement suits).Upvotes: 3