public BinaryNode Insert(BinaryNode root, int num, bool isRight = false) { Count++; var n = BinaryNode.Fac(num); n.Parent = root; if (isRight) { root.Right = n; return(n); } if (root.Left == null) { //Console.WriteLine(n.num); root.Left = n; } else { //Console.WriteLine(n.num); root.Right = n; } NodesTreeIndex.Add(n); return(n); }
public static BinaryTree SetSampleData3() { var l9 = BinaryNode.Fac(9); var t = new BinaryTree(l9); var l12 = t.Insert(l9, 12); var l6 = t.Insert(l9, 6); var l13 = t.Insert(l12, 13); var l25 = t.Insert(l12, 25); t.Insert(l6, 4); t.Insert(l6, 15); t.Insert(l13, 7); t.Insert(l13, 1); t.Insert(l25, 3); t.Insert(l25, 19); return(t); //inorder: 7,13,1,12,3,25,19,9,4,6,15 }
public static BinaryTree SetSampleData1() { var l50R = BinaryNode.Fac(7); var tree = new BinaryTree(l50R); var l25 = tree.Insert(l50R, 25); var l75 = tree.Insert(l50R, 75); //left var l15 = tree.Insert(l25, 15); var l35 = tree.Insert(l25, 35); var l20 = tree.Insert(l15, 20, true); var l30 = tree.Insert(l35, 30); var l40 = tree.Insert(l35, 40); //right var l60 = tree.Insert(l75, 60); var l90 = tree.Insert(l75, 90); tree.Insert(l60, 65, true); tree.Insert(l90, 80); return(tree); }
public static BinaryTree SetSampleData2() { var l10 = BinaryNode.Fac(10); var tree = new BinaryTree(l10); //left var l12 = tree.Insert(l10, 12); var l5 = tree.Insert(l10, 5); tree.Insert(l12, 3); var l4 = tree.Insert(l12, 4); tree.Insert(l5, 11); var l2 = tree.Insert(l5, 2); tree.Insert(l4, 6); tree.Insert(l4, 7); //right tree.Insert(l2, 8, true); //reference: http://cs-people.bu.edu/tvashwin/cs112_spring09/lab06.html //Inorder: 3.12.6.4.7.10.11.5.2.8 return(tree); }
public static BinaryTree SetSampleData() { var l7R = BinaryNode.Fac(7); var tree = new BinaryTree(l7R); var l1 = tree.Insert(l7R, 1); tree.Insert(l1, 0); var l3 = tree.Insert(l1, 3); tree.Insert(l3, 2); var l5 = tree.Insert(l3, 5); tree.Insert(l5, 4); tree.Insert(l5, 6); var l9 = tree.Insert(l7R, 9); tree.Insert(l9, 8); tree.Insert(l9, 10); return(tree); }