Example #1
0
 private void CallInsertNode()
 {
     
     int key = 0;
     if(!int.TryParse(AddNodeValue, out key))
     {
         System.Windows.MessageBox.Show("Invalid key to be inserted\nHint: Try an integer");
     }
     else if (!(selectedNodes != null && selectedNodes.Count > 0)) {
         System.Windows.MessageBox.Show("No node or tree selected");
     }
     else
     {
         Tree tree = new Tree(selectedNodes, Lines);
         if (tree.isValidBST())
         {
             NodeViewModel newNode = new BSTViewModel(new BST() { X = 20, Y = 20, TextOne = key.ToString()});
         newNode.Diameter = 50;
             undoRedo.InsertInUndoRedo(new InsertNodeInTreeCommand(tree, Nodes, selectedNodes, newNode, Lines));
     }
     }
     
 }
Example #2
0
 public BSTViewModel search(BSTViewModel root, int key)
 {
     if (root == null || root.key == key) return root;
     if (root.key < key) return search(ro);
 }