예제 #1
0
 internal static void LookFor(string toFind, BST.Node root)
 {
     if (root.value.English == toFind)
     {
         Console.WriteLine($"Znaleziono {root.value.English} oraz {root.value.Polish}");
     }
     else if (root.value.English.CompareTo(toFind) < 0)
     {
         LookFor(toFind, root.left);
     }
     else
     {
         LookFor(toFind, root.right);
     }
 }
예제 #2
0
        internal static BST.Node OperationsOnTree(LinkedList <dList> dict)
        {
            BST.Node     root = null;
            BST.Tree     bst  = new BST.Tree();
            List <dList> data = dict.ToList();

            Stopwatch watch = Stopwatch.StartNew();

            watch = Stopwatch.StartNew();

            for (int i = 0; i < data.Count; i++)
            {
                root = bst.Insert(root, data[i]);
            }

            watch.Stop();

            List <string> toFind   = utility.Generate("engSR.txt", "toFindS.txt");
            string        fileName = null;

            Console.WriteLine("Name a file in which you want to save Stopwatch data: ");
            fileName = Console.ReadLine();
            TextWriter doWykresu = new StreamWriter(Directory.GetCurrentDirectory() + "/" + fileName + ".csv", true);
            Stopwatch  sw        = new Stopwatch();

            for (int k = 1; k < toFind.Count + 1; k++)
            {
                sw.Start();
                for (int i = 0; i < k; i++)
                {
                    LookFor(toFind[i], root);
                }
                sw.Stop();
                var newLine = string.Format("{0};{1}",
                                            k.ToString(), sw.Elapsed.TotalMilliseconds);
                sw.Reset();
                doWykresu.WriteLine(newLine.ToString());
                Console.WriteLine();
            }
            doWykresu.Close();
            return(root);
        }
예제 #3
0
 internal static void SearchBst(List <string> toFind, BST.Node root)
 {
 }
예제 #4
0
        public static void Lab2Menu(Object data)
        {
            Console.Clear();
            Console.WriteLine("Lab2.");
            Console.WriteLine("1. Wczytanie danych z txt");
            Console.WriteLine("2. wypisz z listy dwukierunkowej");
            Console.WriteLine("3. szukaj w liscie dwukierunkowej");
            Console.WriteLine("4. Wygeneruj drzewo bst");
            Console.WriteLine("5. Szukaj w drzewie bst");
            Console.WriteLine("8. Cofnij");
            Console.Write("Wybierz zadanie");
            Console.WriteLine();
            ConsoleKeyInfo choice = Console.ReadKey(true);
            string         zmiana = choice.Key.ToString();

            switch (zmiana)
            {
            case "D1":
            {
                data = Lab2.ReadWords();
                Console.WriteLine("Wczytano z pliku txt.");
                Console.ReadKey(true);
                Lab2Menu((LinkedList <dList>)data);
            }
            break;

            case "D2":
            {
                if (data.GetType() == typeof(LinkedList <dList>))
                {
                    Lab2.WriteAll((LinkedList <dList>)data);
                    Console.ReadLine();
                    Console.ReadKey(true);
                    Lab2Menu(data);
                }
                else
                {
                    Console.WriteLine($"Loaded Wrong Object: {data.GetType()}. switch to Diffrent function");
                }
            }
            break;

            case "D3":
            {
                if (data.GetType() == typeof(LinkedList <dList>))
                {
                    Console.WriteLine("Podaj nazwe pliku z ktorego chcesz wczytac baze slow do szukania.");
                    string fileNameEng = Console.ReadLine();
                    Console.WriteLine("Podaj nazwe pliku z ktorego chcesz wczytac indexy");
                    string fileNameNum = Console.ReadLine();
                    Lab2.Search(utility.Generate(fileNameEng, fileNameNum), (LinkedList <dList>)data);
                    Console.ReadLine();
                    Console.ReadKey(true);
                    Lab2Menu(data);
                }
                else
                {
                    Console.WriteLine($"Loaded Wrong Object: {data.GetType()}. switch to Diffrent function");
                }
            }
            break;

            case "D4":
            {
                if (data.GetType() == typeof(LinkedList <dList>))
                {
                    if (!((LinkedList <dList>)data).Any())
                    {
                        Console.WriteLine("Read data from file first.");
                        Console.ReadKey(true);
                        Lab2Menu(data);
                    }
                    else
                    {
                        BST.Node root = Lab2.OperationsOnTree((LinkedList <dList>)data);
                        Console.WriteLine("Three has been created.");
                        Console.ReadKey(true);
                        Lab2Menu(root);
                    }
                }
                else
                {
                    Console.WriteLine($"Loaded Wrong Object: {data.GetType()}. switch to Diffrent function");
                }
            }
            break;

            case "D5":
                if (data.GetType() == typeof(BST.Node))
                {
                    Console.WriteLine("Give a file name in which you have a data base of words.");
                    string fileNameEng = Console.ReadLine();
                    Console.WriteLine("Give a file name in which you have randomized indexes");
                    string fileNameNum = Console.ReadLine();
                    Lab2.SearchBst(utility.Generate(fileNameEng, fileNameNum), (BST.Node)data);
                    Console.ReadLine();
                    Console.ReadKey(true);
                    Lab2Menu(data);
                }
                else
                {
                    Console.WriteLine($"Loaded Wrong Object: {data.GetType()}. switch to Diffrent function");
                }

                break;

            case "D8":
            {
                Menu.MainMenu();
            }
            break;

            default:
                Console.WriteLine();
                Console.WriteLine("Niepoprawna akcja!");
                Console.ReadKey(true);
                Lab2Menu(data);
                break;
            }

            Console.WriteLine();
        }