Exemplo n.º 1
0
        public void Run()
        {
            Console.WriteLine("Choose file:"); // Prompt
            Console.WriteLine("1 - tinyL.txt"); // Prompt
            Console.WriteLine("or quit"); // Prompt

            var fileNumber = Console.ReadLine();
            var fieName = string.Empty;
            switch (fileNumber)
            {
                case "1":
                    fieName = "tinyL.txt";
                    break;
                case "quit":
                    return;
                default:
                    return;
            }

            var @in = new In($"Files\\Strings\\{fieName}");
            var content = @in.ReadAllStrings();
            const string regexp = "(A*B|AC)D";
            var grep = new GREP(regexp,content);
            grep.Match();

            Console.ReadLine();
        }
Exemplo n.º 2
0
        public void Run()
        {
            Console.WriteLine("Choose file:"); // Prompt
            Console.WriteLine("1 - shells.txt"); // Prompt
            Console.WriteLine("or quit"); // Prompt

            var fileNumber = Console.ReadLine();
            var fieName = string.Empty;
            switch (fileNumber)
            {
                case "1":
                    fieName = "shells.txt";
                    break;
                case "quit":
                    return;
                default:
                    return;
            }

            var @in = new In($"Files\\Strings\\{fieName}");
            var content = @in.ReadAllStrings();

            var n = content.Length;

            Quick3string.Sort(content);

            for (var i = 0; i < n; i++)
                Console.WriteLine(content[i]);

            Console.ReadLine();
        }
Exemplo n.º 3
0
        public void Run()
        {
            const string fieName = "tobe.txt";

            var @in = new In($"Files\\Collections\\{fieName}");
            var words = @in.ReadAllStrings();

            var queue = new Queue<string>();

            foreach (var word in words)
            {
                queue.Enqueue(word);
            }
            Console.WriteLine("size of queue = {0}", queue.Size());
            foreach (var item in queue)
            {
                Console.WriteLine("item = {0}", item);
            }
            while (!queue.IsEmpty())
            {
                var item = queue.Dequeue();
                Console.WriteLine("item = {0}", item);
            }
            Console.ReadLine();
        }
Exemplo n.º 4
0
        public void Run()
        {
            Console.WriteLine("Choose file:"); // Prompt
            Console.WriteLine("1 - cards.txt"); // Prompt
            Console.WriteLine("2 - cardsUnicode.txt"); // Prompt
            Console.WriteLine("or quit"); // Prompt

            var fileNumber = Console.ReadLine();
            var fieName = string.Empty;
            switch (fileNumber)
            {
                case "1":
                    fieName = "cards.txt";
                    break;
                case "2":
                    fieName = "cardsUnicode.txt";
                    break;
                case "quit":
                    return;
                default:
                    return;
            }

            var @in = new In(string.Format("Files\\Shuffle\\{0}", fieName));
            var cards = @in.ReadAllStrings();

            // shuffle the array
            Knuth.Shuffle(cards.Cast<object>().ToArray());

            // print results.
            foreach (var card in cards)
                Console.WriteLine(card);

            Console.ReadLine();
        }
Exemplo n.º 5
0
        public void Run()
        {
            Console.WriteLine("Choose file:"); // Prompt
            Console.WriteLine("1 - tinyTale.txt"); // Prompt
            Console.WriteLine("or quit"); // Prompt

            var fileNumber = Console.ReadLine();
            var fieName = string.Empty;
            switch (fileNumber)
            {
                case "1":
                    fieName = "tinyTale.txt";
                    break;
                case "quit":
                    return;
                default:
                    return;
            }

            var @in = new In($"Files\\Searching\\{fieName}");
            var words = @in.ReadAllStrings();

            //var list = words.Select(word => new StringComparable(word)).ToList();

            //var listComparable = list.Cast<IComparable>().ToList();
            //var arrayComparable = list.Cast<IComparable>().ToArray();
            var listStrings = words.ToList();

            var deDup =  new DeDup(listStrings);

            deDup.ShowWords();

            Console.ReadLine();
        }
Exemplo n.º 6
0
        public void Run()
        {
            const string fieName = "tobe.txt";

            var @in = new In($"Files\\Collections\\{fieName}");
            var words = @in.ReadAllStrings();

            var stack = new Stack<string>();

            foreach (var word in words)
            {
                stack.Push(word);
            }
            Console.WriteLine("size of stack = {0}", stack.Size());
            foreach (var item in stack)
            {
                Console.WriteLine("item = {0}", item);
            }
            while (!stack.IsEmpty())
            {
                var item = stack.Pop();
                Console.WriteLine("item = {0}", item);
            }
            Console.ReadLine();
        }
Exemplo n.º 7
0
        public void Run()
        {
            Console.WriteLine("Choose file:"); // Prompt
            Console.WriteLine("1 - shellsST.txt"); // Prompt
            Console.WriteLine("or quit"); // Prompt

            var fileNumber = Console.ReadLine();
            var fieName = string.Empty;
            switch (fileNumber)
            {
                case "1":
                    fieName = "shellsST.txt";
                    break;
                case "quit":
                    return;
                default:
                    return;
            }

            var @in = new In($"Files\\Strings\\{fieName}");
            var content = @in.ReadAllStrings();
            var st = new TrieST<Integer>();
            for (var i = 0; i< content.Length; i++)
            {
                st.Put(content[i], i);
            }

            // print results
            if (st.Size() < 100)
            {
                Console.WriteLine("keys(\"\"):");
                foreach (var key in st.Keys())
                {
                    Console.WriteLine($"{key} {st.Get(key).Value}");
                }
                Console.WriteLine();
            }

            Console.WriteLine("longestPrefixOf(\"shellsort\"):");
            Console.WriteLine(st.LongestPrefixOf("shellsort"));
            Console.WriteLine();

            Console.WriteLine("longestPrefixOf(\"quicksort\"):");
            Console.WriteLine(st.LongestPrefixOf("quicksort"));
            Console.WriteLine();

            Console.WriteLine("keysWithPrefix(\"shor\"):");
            foreach (var s in st.KeysWithPrefix("shor"))
                Console.WriteLine(s);
            Console.WriteLine();

            Console.WriteLine("keysThatMatch(\".he.l.\"):");
            foreach (var s in st.KeysThatMatch(".he.l."))
                Console.WriteLine(s);

            Console.ReadLine();
        }
Exemplo n.º 8
0
        public void Run()
        {
            Console.WriteLine("Choose file:"); // Prompt
            Console.WriteLine("1 - tiny.txt"); // Prompt
            Console.WriteLine("2 - words3.txt"); // Prompt
            Console.WriteLine("or quit"); // Prompt

            var fileNumber = Console.ReadLine();
            var fieName = string.Empty;
            switch (fileNumber)
            {
                case "1":
                    fieName = "tiny.txt";
                    break;
                case "2":
                    fieName = "words3.txt";
                    break;
                case "quit":
                    return;
                default:
                    return;
            }

            var @in = new In(string.Format("Files\\Sorting\\{0}", fieName));
            var words = @in.ReadAllStrings();

            var list = words.Select(word => new StringComparable(word)).ToList();

            var listComparable = list.Cast<IComparable>().ToList();
            var arrayComparable = list.Cast<IComparable>().ToArray();
            var listStrings = words.ToList();

            // sort list
            Selection.Sort(listComparable);
            // print results.
            AbstractSort.Show(listComparable);

            Console.WriteLine("-----------------------------------------------------");

            // sort array
            Selection.Sort(arrayComparable);
            // print results.
            AbstractSort.Show(arrayComparable);

            Console.WriteLine("-----------------------------------------------------");

            // sort list
            Selection<string>.Sort(listStrings, new StringComparer());
            // print results
            Selection<string>.Show(listStrings);

            Console.ReadLine();
        }
Exemplo n.º 9
0
        public void Run()
        {
            var filesList = new List<string> { "m1.txt", "m2.txt", "m3.txt" };
            var wordsList = new List<List<string>>();

            foreach (var fileName in filesList)
            {
                var @in = new In($"Files\\Sorting\\{fileName}");
                var words = @in.ReadAllStrings();
                wordsList.Add(words.ToList());
            }

            var multiway = new Multiway(wordsList);

            multiway.ShowWords();

            Console.ReadLine();
        }
Exemplo n.º 10
0
        public void Run()
        {
            Console.WriteLine("Choose file:"); // Prompt
            Console.WriteLine("1 - words3.txt"); // Prompt
            Console.WriteLine("2 - pi.txt"); // Prompt
            Console.WriteLine("or quit"); // Prompt

            var fileNumber = Console.ReadLine();
            var fieName = string.Empty;
            switch (fileNumber)
            {
                case "1":
                    fieName = "words3.txt";
                    break;
                case "2":
                    fieName = "pi.txt";
                    break;
                case "quit":
                    return;
                default:
                    return;
            }

            var @in = new In($"Files\\Strings\\{fieName}");
            var content = @in.ReadAllStrings();

            var n = content.Length;
            // check that strings have fixed length
            var w = content[0].Length;
            for (var i = 0; i < n; i++)
            {
                if (content[i].Length == w) continue;
                Console.WriteLine("Strings must have fixed length");
                Console.ReadLine();
                return;
            }

            LSD.Sort(content, w);

            for (var i = 0; i < n; i++)
                Console.WriteLine(content[i]);

            Console.ReadLine();
        }
Exemplo n.º 11
0
        public void Run()
        {
            Console.WriteLine("Choose file:"); // Prompt
            Console.WriteLine("1 - tinyPQ.txt"); // Prompt
            Console.WriteLine("or quit"); // Prompt

            var fileNumber = Console.ReadLine();
            var fieName = string.Empty;
            switch (fileNumber)
            {
                case "1":
                    fieName = "tinyIndexPQ.txt";
                    break;
                case "quit":
                    return;
                default:
                    return;
            }

            var @in = new In($"Files\\Sorting\\{fieName}");
            var words = @in.ReadAllStrings();

            //var list = words.Select(word => new StringComparable(word)).ToList();

            //var listComparable = list.Cast<IComparable>().ToList();
            //var arrayComparable = list.Cast<IComparable>().ToArray();
            var listStrings = words.ToList();

            var pq = new IndexMaxPQ<string>(listStrings.Count);
            //Fill Priority Queue
            for (var i = 0; i < listStrings.Count; i++)
            {
                 pq.Insert(i, listStrings[i]);

            }
            // print results
            foreach (var item in pq)
            {
                Console.WriteLine(pq.KeyOf(item));
            }

            Console.ReadLine();
        }
Exemplo n.º 12
0
        public void Run()
        {
            Console.WriteLine("Choose file:"); // Prompt
            Console.WriteLine("1 - tinyPQ.txt"); // Prompt
            Console.WriteLine("or quit"); // Prompt

            var fileNumber = Console.ReadLine();
            var fieName = string.Empty;
            switch (fileNumber)
            {
                case "1":
                    fieName = "tinyPQ.txt";
                    break;
                case "quit":
                    return;
                default:
                    return;
            }

            var @in = new In(string.Format("Files\\Sorting\\{0}", fieName));
            var words = @in.ReadAllStrings();

            //var list = words.Select(word => new StringComparable(word)).ToList();

            //var listComparable = list.Cast<IComparable>().ToList();
            //var arrayComparable = list.Cast<IComparable>().ToArray();
            var listStrings = words.ToList();

            var pq = new MinPQ<string>(new StringComparer());
            //Fill Priority Queue
            foreach (var word in listStrings)
            {
                pq.Insert(word);
            }
            // print results
            foreach (var item in pq)
            {
                Console.WriteLine(item);
            }

            Console.ReadLine();
        }
Exemplo n.º 13
0
        public void Run()
        {
            const string fieName = "tobe.txt";

            var @in = new In($"Files\\Collections\\{fieName}");
            var words = @in.ReadAllStrings();

            var bag = new Bag<string>();

            foreach (var word in words)
            {
                bag.Add(word);
            }
            Console.WriteLine("size of bag = {0}", bag.Size());
            foreach (var item in bag)
            {
                Console.WriteLine("item = {0}", item);
            }
            Console.ReadLine();
        }
Exemplo n.º 14
0
        public void Run()
        {
            var fileIndex = new FileIndex();

            var fileNames = new List<string> { "ex1.txt", "ex2.txt", "ex3.txt", "ex4.txt" };

            foreach (var fileName in fileNames)
            {
                var @in = new In($"Files\\Searching\\{fileName}");
                var words = @in.ReadAllStrings();
                fileIndex.CreateIndex(fileName, words);
            }

            fileIndex.ShowFilesByQuery("was");
            Console.WriteLine("------------------------------------");
            fileIndex.ShowFilesByQuery("age");
            Console.WriteLine("------------------------------------");
            fileIndex.ShowFilesByQuery("wisdom");

            Console.ReadLine();
        }
Exemplo n.º 15
0
        public void Run()
        {
            Console.WriteLine("Choose file:"); // Prompt
            Console.WriteLine("1 - tiny.txt"); // Prompt
            Console.WriteLine("2 - words3.txt"); // Prompt
            Console.WriteLine("or quit"); // Prompt

            var fileNumber = Console.ReadLine();
            string fieName;
            switch (fileNumber)
            {
                case "1":
                    fieName = "tiny.txt";
                    break;
                case "2":
                    fieName = "words3.txt";
                    break;
                case "quit":
                    return;
                default:
                    return;
            }

            var @in = new In($"Files\\Sorting\\{fieName}");
            var words = @in.ReadAllStrings();

            var list = words.Select(word => new StringComparable(word)).ToList();

            var listComparable = list.Cast<IComparable>().ToList();
            var arrayComparable = list.Cast<IComparable>().ToArray();
            var listStrings = words.ToList();

            // sort list
            QuickX.Sort(listComparable);
            // print results.
            AbstractSort.Show(listComparable);

            Console.ReadLine();
        }