/// <summary> /// Remove button click handler /// Removes entered value from chosen tree /// </summary> private void btnRemove_Click(object sender, EventArgs e) { try { int value = Convert.ToInt32(tbRemove.Text); if (value > 9999 || value < -999) { throw new OverflowException("Please enter number between [-999;9999]."); } switch (this.activeTab) { case Tab.BST: activeRoot = Binary_Search_Tree.Remove(activeRoot, value); bst_root = activeRoot; break; case Tab.AVL: activeRoot = AVL_Tree.Remove(activeRoot, value); avl_root = activeRoot; break; case Tab.RBT: break; case Tab.SPL: activeRoot = AVL_Tree.Remove(spl_root, value); spl_root = activeRoot; break; } activePictureBox.Invalidate(); } catch (OverflowException ex) { MessageBox.Show(ex.Message, ex.GetType().Name); } catch (FormatException) { } tbRemove.Text = string.Empty; }
/// <summary> /// Insert button click handler /// Inserts a value into chosen tree /// </summary> private void btnInsert_Click(object sender, EventArgs e) { try { int value = Convert.ToInt32(tbInsert.Text); if (value > 9999 || value < -999) { throw new OverflowException("Please enter number between [-999;9999]."); } switch (this.activeTab) { case Tab.BST: if (this.total_nodes > 35) { MessageBox.Show("Node limit is set to 35!", "Warning"); return; } activeRoot = Binary_Search_Tree.Insert(activeRoot, value); bst_root = activeRoot; break; case Tab.AVL: if (this.total_nodes > 60) { MessageBox.Show("Node limit is set to 60!", "Warning"); return; } activeRoot = AVL_Tree.Insert(activeRoot, value); avl_root = activeRoot; break; case Tab.RBT: break; case Tab.SPL: if (this.total_nodes > 35) { MessageBox.Show("Node limit is set to 35!", "Warning"); return; } activeRoot = Splay_Tree.Insert(activeRoot, value); spl_root = activeRoot; break; } activePictureBox.Invalidate(); } catch (OverflowException ex) { MessageBox.Show(ex.Message, ex.GetType().Name); } catch (FormatException) { } tbInsert.Text = string.Empty; }