node search (node, key) {
if node is null then return null;
if node.key = key then
return node
if key < node then
return search (node.left, key);
else
return search (node.right, key);
==============================================
bt = new TBinarySTree();
bt.insert ("Canis Minoris", 5.37);
bt.insert ("Gamma Cancri", 4.66);
bt.insert ("Phi Centauri", 3.83);
bt.insert ("Kappa Tauri", 4.21);
TTreeNode symbol = bt.findSymbol ("Phi Centauri");
if (symbol != null)
Console.WriteLine ("Star {1} has magnitude = {0}", symbol.name, symbol.value);
No comments:
Post a Comment