private void button_test_Click(object sender, EventArgs e) { var count = int.Parse(textBox2.Text); using var writer = new StreamWriter("test.txt"); var value = _rnd.Next(int.MinValue, int.MaxValue); if (count > 0) { _tree = new TwoThreeFourTree(value); TwoThreeFourTree.NumberIterations = 1; } for (var i = 0; i < count - 1; i++) { if (i == count - 2) { TwoThreeFourTree.NumberIterations = 0; } value = _rnd.Next(int.MinValue, int.MaxValue); TwoThreeFourTree.Add(value, _tree); } if (renderBox.Checked) { RenderTree(); } iterInfo.Text = $@"Кол-во итераций: {TwoThreeFourTree.NumberIterations}"; }
private void button_add_Click(object sender, EventArgs e) { var value = Int32.Parse(textBox1.Text); if (_tree == null) { _tree = new TwoThreeFourTree(value); } else { TwoThreeFourTree.Add(value, _tree); } textBox1.Text = string.Empty; RenderTree(); }
private void load_Click(object sender, EventArgs e) { using var reader = new StreamReader("test.txt"); while (!reader.EndOfStream) { var val = int.Parse(reader.ReadLine() !); if (_tree == null) { _tree = new TwoThreeFourTree(val); } else { TwoThreeFourTree.Add(val, _tree); } if (renderBox.Checked) { RenderTree(); } } }
private void RenderTree() { if (_tree != null) { AddInTree(TwoThreeFourTree.GetHead(_tree)); } using (var gr = this.CreateGraphics()) { // Arrange the tree once to see how big it is. float xmin = 0, ymin = 0; _root.Arrange(gr, ref xmin, ref ymin); // Arrange the tree again to center it. xmin = (ClientSize.Width - xmin) / 2; //ymin = (this.ClientSize.Height - ymin) / 2; _root.Arrange(gr, ref xmin, ref ymin); } // Redraw. Refresh(); }
private void AddInTree(TwoThreeFourTree tree, TreeNode <CircleNode> parent = null) { if (tree == null) { if (checkBox1.Checked) { parent?.AddChild(new TreeNode <CircleNode>(new CircleNode("[]"))); } return; } var text = ""; for (var i = 0; i < tree.Values.Count; i++) { text += tree.Values[i]; if (i != tree.Values.Count - 1) { text += " | "; } } text += ""; var node = new TreeNode <CircleNode>(new CircleNode(text)); if (tree.Parent == null) { _root = node; } else { parent?.AddChild(node); } parent = node; foreach (var t in tree.Children) { AddInTree(t, parent); } }
public Form1() { InitializeComponent(); _tree = null; }