AdBrite

Your Ad Here

Thursday, April 21, 2011

A simple Binary Search Tree written in C#

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);
==============================================
// Create a new binary tree
bt = new TBinarySTree();

// Insert data
bt.insert ("Canis Minoris", 5.37);
bt.insert ("Gamma Cancri", 4.66);
bt.insert ("Phi Centauri", 3.83);
bt.insert ("Kappa Tauri", 4.21);
 
// Retrieve data  
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

BidVertiser

pocket cents

PocketCents Local Online Advertising