示例#1
0
        public BSTree RandomChoiceTree(string filePath, List <string> l1, List <string> l2)
        {
            char[]        splitter     = { '\n', '\r', ',' };
            Random        random       = new Random();
            StreamReader  streamReader = new StreamReader(File.OpenRead(filePath));
            List <string> list1        = new List <string>();
            List <string> list2        = new List <string>();


            while (!streamReader.EndOfStream)
            {
                string readLine = streamReader.ReadLine();

                if (!String.IsNullOrWhiteSpace(readLine))
                {
                    l1.Add(readLine);
                }
            }

            for (int i = 0; i < 10000; i++)
            {
                l2.Add(l1[random.Next(0, l1.Count)]);
            }

            for (int i = 0; i < l2.Count; i++)
            {
                string[] temp    = l2[i].Split(splitter);
                string   holding = "";
                for (int j = 0; j < temp.Length; j++)
                {
                    if (j == 0)
                    {
                        list1.Add(temp[j]);
                    }
                    else
                    {
                        holding += (temp[j] + " ");
                    }
                }
                list2.Add(holding);
            }
            var    a1     = list1.ToArray();
            var    a2     = list2.ToArray();
            BSTree bsTree = new BSTree();

            for (int i = 0; i < a1.Length; i++)
            {
                Node node = new Node(long.Parse(a1[i]), a2[i]);
                Insert(bsTree, node);
            }

            return(bsTree);
        }
示例#2
0
        public void Driver(string[] checkList, BSTree bSTree)
        {
            var timer = new Stopwatch();

            for (int i = 0; i < checkList.Length; i++)
            {
                timer.Start();
                Node result = TreeSearch(bSTree.root, long.Parse(checkList[i]));
                timer.Stop();
                if (result == null)
                {
                    Console.Write("Node not found within Tree ");
                    Console.WriteLine("Time of search: " + timer.Elapsed);
                    timer.Reset();
                }
                else
                {
                    Console.Write("Found Key: " + result.key + " with data " + result.data + " ");
                    Console.WriteLine("Time of search: " + timer.Elapsed);
                    timer.Reset();
                }
            }
        }