//删除叶子节点失败 private static void TestRemove(int[] arr, int removeIndex) { BSTree <int> bSTree = new BSTree <int>(); for (int i = 0; i < arr.Length; ++i) { bSTree.Insert(arr[i]); } BinTreeLogHelper <int> .Log(bSTree.Root, false, false); Console.WriteLine("Remove:" + arr[removeIndex]); bSTree.Remove(arr[removeIndex]); BinTreeLogHelper <int> .Log(bSTree.Root, false, false); Console.WriteLine(); LogBinTreeCheck <int> .Check(bSTree.TraverseLevel(bSTree.Root)); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); }
public static void Test() { SplayTree <int> splayTree = new SplayTree <int>(); int[] arr = new int[] { 22, 10, 8, 15, 17, 20, 19, 21, 12, 13 }; //int[] arr = new int[] { 10, 20, 8, 19, 15, 17, 21}; //int[] arr = new int[] { 10, 20, 8, 19}; for (int i = 0; i < arr.Length; ++i) { //Console.WriteLine("Insert:" + arr[i]); splayTree.Insert(arr[i]); //BinTreeLogHelper<int>.Log(splayTree.Root, true); //Console.WriteLine(); List <BinNode <int> > list = new List <BinNode <int> >(); LogBinTreeCheck <int> .Check(list); // //list = splayTree.TraverseLevel(splayTree.Root); //for (int j = 0; j < list.Count; ++j) //{ // BinNode<int> ttt = list[j]; // int data = ttt.Value; // while (ttt.ParentNode != null) // { // ttt = ttt.ParentNode; // if (data == ttt.Value) // { // int a = 0; // } // } //} } BinTreeLogHelper <int> .Log(splayTree.Root, false, false); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); for (int i = 0; i < arr.Length; ++i) { Console.WriteLine("Remove:" + arr[i]); splayTree.Remove(arr[i]); BinTreeLogHelper <int> .Log(splayTree.Root, false, false); Console.WriteLine(); List <BinNode <int> > list = splayTree.TraverseLevel(splayTree.Root); Console.WriteLine(); } //BinNode<int> root = splayTree.Insert(8); //BinNode<int> node10 = new BinNode<int>(10); //root.InsertAsRc(node10); //BinNode<int> node20 = new BinNode<int>(20); //node10.InsertAsRc(node20); //BinTreeLogHelper<int>.Log(splayTree.Root, true); ////splayTree.Search(19); ////BinTreeLogHelper<int>.Log(splayTree.Root, true); //Console.WriteLine(); //Console.WriteLine(); //splayTree.Insert(19); //BinTreeLogHelper<int>.Log(splayTree.Root, true); }
public static void Test() { List <BinNode <int> > list = new List <BinNode <int> >(); BSTree <int> bsTree = new BSTree <int>(); for (int i = 0; i < 9; ++i) { bsTree.Insert(i); } BinTreeLogHelper <int> .Log(bsTree.Root, false, false); //{ // int[] aaaRR = new int[] { 16, 9, 6, 22 };s // BSTree<int> bSTree = new BSTree<int>(); // for (int i = 0; i < aaaRR.Length; ++i) // { // bSTree.Insert(aaaRR[i]); // } // BinTreeLogHelper<int>.Log(bSTree.Root, false); // Console.WriteLine(); // list = bSTree.TraverseLevel(bSTree.Root); // Console.WriteLine(); // for (int n = 0; n < list.Count; ++n) // { // BinNode<int> node = list[n]; // Console.WriteLine(list[n].Value.ToString() + " heigh:" + list[n].Height + " deep:" + list[n].Deep); // int deep = -1; // while (null != node) // { // ++deep; // node = node.ParentNode; // } // if (deep != list[n].Deep) // { // Console.WriteLine(list[n].Value.ToString() + " deep:" + list[n].Deep + " Error Error Error Error Error Error"); // } // } // bSTree.Remove(6); // BinTreeLogHelper<int>.Log(bSTree.Root, false); // Console.WriteLine(); // list = bSTree.TraverseLevel(bSTree.Root); // Console.WriteLine(); // for (int n = 0; n < list.Count; ++n) // { // BinNode<int> node = list[n]; // Console.WriteLine(list[n].Value.ToString() + " heigh:" + list[n].Height + " deep:" + list[n].Deep); // int deep = -1; // while (null != node) // { // ++deep; // node = node.ParentNode; // } // if (deep != list[n].Deep) // { // Console.WriteLine(list[n].Value.ToString() + " deep:" + list[n].Deep + " Error Error Error Error Error Error"); // } // } //} int[] arr = new int[] { 10, 8, 15, 17, 20, 19, 21, 12, 13, 6, 9, 16, 22, }; //for (int i = 0; i < arr.Length; ++i) //{ // TestRemove(arr, i); //} { BSTree <int> bSTree = new BSTree <int>(); for (int i = 0; i < arr.Length; ++i) { bSTree.Insert(arr[i]); //BinTreeLogHelper<int>.Log(bSTree.Root, false); //Console.WriteLine(); //list = bSTree.TraverseLevel(bSTree.Root); //Console.WriteLine(); //for (int n = 0; n < list.Count; ++n) //{ // BinNode<int> node = list[n]; // Console.WriteLine(list[n].Value.ToString() + " heigh:" + list[n].Height + " deep:" + list[n].Deep); // int deep = -1; // while (null != node) // { // ++deep; // node = node.ParentNode; // } // if (deep != list[n].Deep) // { // Console.WriteLine(list[n].Value.ToString() + " deep:" + list[n].Deep + " Error Error Error Error Error Error"); // } //} //list = bSTree.TraverseLevel(bSTree.Root); //Console.WriteLine(); //for (int n = 0; n < list.Count; ++n) //{ // BinNode<int> node = list[n]; // int heigh = node.Height; // //bSTree.UpdateHeight(node); // if (heigh != node.Height) // { // Console.WriteLine(list[n].Value.ToString() + " heigh:" + list[n].Height + " Error Error Error Error Error Error"); // } //} } BinTreeLogHelper <int> .Log(bSTree.Root, false, false); Console.WriteLine(); Console.WriteLine(); //list = bSTree.TraverseLevel(bSTree.Root); //for (int n = 0; n < list.Count; ++n) //{ // BinNode<int> node = list[n]; // int deep = -1; // while (null != node) // { // ++deep; // node = node.ParentNode; // } // if (deep != list[n].Deep) // { // Console.WriteLine(list[n].Value.ToString() + " deep:" + list[n].Deep + " Error Error Error Error Error Error"); // } //} Console.WriteLine(); for (int i = 0; i < arr.Length; ++i) { Console.WriteLine("Remove:" + arr[i]); bSTree.Remove(arr[i]); BinTreeLogHelper <int> .Log(bSTree.Root, false, false); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); LogBinTreeCheck <int> .Check(bSTree.TraverseLevel(bSTree.Root)); Console.WriteLine(); list = bSTree.TraverseLevel(bSTree.Root); Console.WriteLine(); for (int n = list.Count - 1; n >= 0; --n) { BinNode <int> node = list[n]; int heigh = node.Height; //bSTree.UpdateHeight(node); if (heigh == node.Height) { Console.WriteLine(list[n].Element.ToString() + " heigh:" + list[n].Height + " Error Error Error Error Error Error"); } } //for (int n = 0; n < list.Count; ++n) //{ // BinNode<int> node = list[n]; // int heigh = node.Height; // bSTree.UpdateHeight(node); // if (heigh != node.Height) // { // Console.WriteLine(list[n].Value.ToString() + " heigh:" + list[n].Height + " Error Error Error Error Error Error"); // } //} Console.WriteLine(); } } //{ // BSTree<int> bSTree = new BSTree<int>(); // bSTree.Insert(10); // BinTreeLogHelper<int>.Log(bSTree.Root, false); // Console.WriteLine(); // bSTree.Remove(10); // BinTreeLogHelper<int>.Log(bSTree.Root, false); //} }