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(); }
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($"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 MergeX.Sort(listComparable); // print results. AbstractSort.Show(listComparable); Console.WriteLine("-----------------------------------------------------"); // sort array MergeX.Sort(arrayComparable); // print results. AbstractSort.Show(arrayComparable); Console.WriteLine("-----------------------------------------------------"); // sort list MergeX <string> .Sort(listStrings, new StringComparer()); // print results MergeX <string> .Show(listStrings); Console.ReadLine(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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 IndexMinPQ <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(); }
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 inFilter = new In($"Files\\Searching\\list.txt"); var filter = inFilter.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 blackFilter = new BlackFilter(filter); foreach (var word in words) { blackFilter.Filter(word); } Console.ReadLine(); }
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(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 Heap.Sort(listComparable); // print results. AbstractSort.Show(listComparable); Console.ReadLine(); }
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(); }
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(); }
/// <summary> /// Sort a small text file. /// </summary> /// <param name="streamName">The name of the file to sort.</param> /// <param name="sortingAlgorithm">The algorithm to use for sorting.</param> /// <returns>The sorted items.</returns> public static string[] SortCommon(string streamName, ISortingAlgorithm sortingAlgorithm) { Contract.Ensures(null != Contract.Result<string[]>()); if (null == sortingAlgorithm) { throw new ArgumentNullException("sortingAlgorithm"); } string[] testItems; using (In inStream = new In(streamName)) { testItems = inStream.ReadAllStrings(); } if (null == testItems) { throw new InternalTestFailureException("No items to test"); } sortingAlgorithm.Sort(testItems); return testItems; }
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(); }
/// <summary> /// Test a queue using a stream (file) with strings and taking the minus sign /// as an indication to de-queue an item. /// </summary> /// <param name="streamName">The stream from where the input strings will be read.</param> /// <param name="queue">The queue to operate on.</param> /// <param name="expectedResults">The expected sequence of items removed by the minus signs.</param> /// <param name="expectedRemainder"> /// The expected amount of items in the queue after all the removals have been processed /// </param> public static void StringPQTest(string streamName, PQCollection<string> queue, string[] expectedResults, int expectedRemainder) { Contract.Requires<ArgumentNullException>(queue != null, "queue"); Contract.Requires<ArgumentNullException>(expectedResults != null, "expectedResults"); string[] testItems; int expectedIndex = 0; using (In inStream = new In(streamName)) { testItems = inStream.ReadAllStrings(); } if (null == testItems) { throw new InternalTestFailureException("No items to test."); } foreach (string testItem in testItems) { if (0 != string.CompareOrdinal(testItem, "-")) { queue.Enqueue(testItem); } else if (1 > queue.Count) { throw new InternalTestFailureException("Queue underflow."); } else if (expectedResults.Length <= expectedIndex) { throw new InternalTestFailureException("Expected Results underflow."); } else { Assert.AreEqual(expectedResults[expectedIndex++], queue.Dequeue()); } } Assert.AreEqual(expectedRemainder, queue.Count()); }
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(); }
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 TST <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(\"shell\"):"); Console.WriteLine(st.LongestPrefixOf("shell")); 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(); }
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 TrieSET <string>(); foreach (var word in content) { st.Add(word); } // print results if (st.Size() < 100) { Console.WriteLine("keys(\"\"):"); foreach (var key in st) { Console.WriteLine($"{key}"); } Console.WriteLine(); } Console.WriteLine("longestPrefixOf(\"shellsort\"):"); Console.WriteLine(st.LongestPrefixOf("shellsort")); Console.WriteLine(); Console.WriteLine("longestPrefixOf(\"xshellsort\"):"); Console.WriteLine(st.LongestPrefixOf("xshellsort")); Console.WriteLine(); Console.WriteLine("keysWithPrefix(\"shor\"):"); foreach (var s in st.KeysWithPrefix("shor")) { Console.WriteLine(s); } Console.WriteLine(); Console.WriteLine("keysWithPrefix(\"shortening\"):"); foreach (var s in st.KeysWithPrefix("shortening")) { Console.WriteLine(s); } Console.WriteLine(); Console.WriteLine("keysThatMatch(\".he.l.\"):"); foreach (var s in st.KeysThatMatch(".he.l.")) { Console.WriteLine(s); } Console.ReadLine(); }