static void Main(string[] args) { for (int j = 0; j < 15; j++) { Tree <int> tree = new Tree <int>(); // var j = 15; int lastInsertElement = new int(); using (StreamReader sr = new StreamReader((j + 1) + ".txt")) { while (!sr.EndOfStream) { string[] line = sr.ReadLine().Split(new char[] { ' ' }); for (int i = 0; i < line.Length; i++) { if (line[i] == "") { break; } int element = Convert.ToInt32(line[i]); tree.Insert(element); lastInsertElement = element; } } } Stopwatch sw = new Stopwatch(); sw.Start(); lastInsertElement = 7; bool isFind = tree.Search(lastInsertElement); sw.Stop(); Console.WriteLine(sw.ElapsedTicks); } Console.ReadKey(); }
static void Main(string[] args) { Node root = null; Tree BST = new Tree(); for (int i = 0; i < BST.ns.Length; i++) { DateTime dat1 = DateTime.Now; BST.InsertIncreasing(BST.FillIncreasing(BST.ns[i]), ref root, BST.ns.Length); DateTime dat2 = DateTime.Now; var span = dat2 - dat1; Debug.Assert(BST.IsBST(root)); Console.WriteLine(span); int[] shuffle = BST.FillIncreasing(BST.ns[i]); BST.Shuffle(ref shuffle, BST.ns[i]); DateTime dat3 = DateTime.Now; for (int j = 0; j < shuffle.Length; j++) { BST.Search(root, shuffle[j]); } DateTime dat4 = DateTime.Now; var span2 = dat4 - dat3; Console.WriteLine(span2); } }
private static void SearchData(Tree tree, int numberOfTestNodes, TestData.TestDataOrder testDataOrder) { TestData testData = new TestData(numberOfTestNodes, testDataOrder); Console.Write(" Searching tree for values from 0 to {0}. ", tree.Count - 1); Stopwatch stopwatch = Stopwatch.StartNew(); foreach (int key in testData.Keys) { tree.Search(key); } stopwatch.Stop(); Console.WriteLine("Time elapsed (ms) : {0}", stopwatch.ElapsedMilliseconds); }
public static void Main(string[] args) { Tree tree = new Tree(); Random rnd = new Random(); for (int i = 0; i < 20; i++) { tree.AddValue(rnd.Next(100)); } tree.Traverse(); int search = int.Parse(Console.ReadLine()); Node found = tree.Search(search); if (found != null) { Console.WriteLine($"Found {found.value}"); } Console.ReadKey(); }
static void Main(string[] args) { Tree Data = new Tree(); //Adding Data in a tree Data.Add(12); Data.Add(4); Data.Add(9); Data.Add(50); Data.Add(1); Console.WriteLine("PreOrder"); Data.Print(); Console.WriteLine("Level Order"); Data.PrintLevelOrder(); Console.WriteLine("Spiral Order"); Data.PrintSpiralOrder(); Data.Search(-1); Console.ReadKey(); }