Esempio n. 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));
     }
     }
     
 }
Esempio n. 2
0
 private void CallRemoveNodeInTree()
 {
     Tree tree = new Tree(selectedNodes,Lines);
     Tree wholeTree = new Tree(tree.getWholeTree(),Lines);
     if (selectedNodes == null || selectedNodes.Count != 1)
         System.Windows.MessageBox.Show("You have to mark excactly one node");
     else if (!wholeTree.isValidBST())
         System.Windows.MessageBox.Show("This tree is not valid");
     else
     {
         
         undoRedo.InsertInUndoRedo(new RemoveNodeInTreeCommand(tree, Nodes, selectedNodes, Lines));
     }        
 }