/// <summary> /// Search button click handler /// Finds and marks node if found /// </summary> private void btnSearch_Click(object sender, EventArgs e) { activePictureBox.Invalidate(); try { int value = Convert.ToInt32(tbSearch.Text); if (value > 9999 || value < -999) { throw new OverflowException("Please enter number between [-999;9999]."); } Node ptrTemp = null; ptrTemp = (from node in Node.Search(activeRoot) where node.value == value select node).FirstOrDefault(); if (ptrTemp == null) { MessageBox.Show("Entered value does not exist!", "Search Result"); } else { // SPlay if (activeRoot == spl_root) { activeRoot = Splay_Tree.Splay(activeRoot, value); spl_root = activeRoot; tbSearch.Text = string.Empty; return; } else { // Camera Focus minimap_x = (ptrTemp.x / 10) - 97 / 2; minimap_y = (ptrTemp.y / 10) - 51 / 2 + CRadius; } this.activePictureBox.Location = new Point(minimap_x * -10, minimap_y * -10 + CRadius); // Marking found node using (var graphics = activePictureBox.CreateGraphics()) { activePictureBox.Update(); graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.DrawEllipse(new Pen(Color.Red, 3), ptrTemp.x, ptrTemp.y, CDiameter, CDiameter); } pbMinimap.Invalidate(); } } catch (OverflowException ex) { MessageBox.Show(ex.Message, ex.GetType().Name); } catch (FormatException) { } tbSearch.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; }