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() { 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() { 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() { Console.WriteLine("Choose file:"); // Prompt Console.WriteLine("1 - tinyT.txt"); // Prompt Console.WriteLine("2 - tinyW.txt"); // Prompt Console.WriteLine("3 - largeT.txt"); // Prompt Console.WriteLine("4 - largeW.txt"); // Prompt Console.WriteLine("or quit"); // Prompt var fileNumber = Console.ReadLine(); var fieName = string.Empty; switch (fileNumber) { case "1": fieName = "tinyT.txt"; break; case "2": fieName = "tinyW.txt"; break; case "3": fieName = "largeT.txt"; break; case "4": fieName = "largeW.txt"; break; case "quit": return; default: return; } var @in = new In($"Files\\BinarySearch\\{fieName}"); @in.ReadAllInts(); }
public void Run() { Console.WriteLine("Choose file:"); // Prompt Console.WriteLine("1 - abra.txt"); // Prompt Console.WriteLine("2 - pi.txt"); // Prompt Console.WriteLine("or quit"); // Prompt var fileNumber = Console.ReadLine(); var alpha = string.Empty; var fieName = string.Empty; switch (fileNumber) { case "1": fieName = "abra.txt"; alpha = "ABCDR"; break; case "2": fieName = "pi.txt"; alpha = "0123456789"; break; case "quit": return; default: return; } var @in = new In($"Files\\Strings\\{fieName}"); var content = @in.ReadAll(); var count = new Count(alpha); count.Run(content); Console.ReadLine(); }
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 - jobs.txt"); // Prompt Console.WriteLine("or quit"); // Prompt var fileNumber = Console.ReadLine(); string fileName; char delimiter; switch (fileNumber) { case "1": fileName = "jobs.txt"; delimiter = '/'; break; case "quit": return; default: return; } var @in = new In($"Files\\Graphs\\{fileName}"); var lines = !fileName.EndsWith("zip") ? @in.ReadAllLines() : @in.ReadAllLinesFromZip(); var sg = new SymbolDigraph(lines, delimiter); Console.WriteLine(sg.G); var topological = new Topological(sg.G); foreach (int v in topological.Order()) { Console.WriteLine(sg.Name(v)); } 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() { 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(); }
public void Run() { Console.WriteLine("Choose file:"); // Prompt Console.WriteLine("1 - genomeTiny.txt"); // Prompt Console.WriteLine("2 - genomeVirus.txt"); // Prompt Console.WriteLine("or quit"); // Prompt var fileNumber = Console.ReadLine(); var fieName = string.Empty; switch (fileNumber) { case "1": fieName = "genomeTiny.txt"; break; case "2": fieName = "genomeVirus.txt"; break; case "quit": return; default: return; } var @in = new In($"Files\\Strings\\{fieName}"); var content = @in.ReadAll(); var genome = new Genome(); genome.Compress(content); var list = new List<byte>(); var bytes = genome.ToByteList(list, content); genome.Expand(bytes.ToArray()); Console.ReadLine(); }
public void Run() { Console.WriteLine("Choose file:"); // Prompt Console.WriteLine("1 - abra.txt"); // Prompt Console.WriteLine("or quit"); // Prompt var fileNumber = Console.ReadLine(); var fieName = string.Empty; switch (fileNumber) { case "1": fieName = "abra.txt"; break; case "quit": return; default: return; } var @in = new In($"Files\\Strings\\{fieName}"); var content = @in.ReadAll(); var binaryDump = new BinaryDump(content, 16); binaryDump.Dump(); Console.ReadLine(); }
public void Run() { Console.WriteLine("Choose file:"); // Prompt Console.WriteLine("1 - routes.txt"); // Prompt Console.WriteLine("2 - movies.txt"); // Prompt //Console.WriteLine("3 - largeG.zip"); // Prompt Console.WriteLine("or quit"); // Prompt var fileNumber = Console.ReadLine(); string fileName; char delimiter; List<string> names; switch (fileNumber) { case "1": fileName = "routes.txt"; delimiter = '\u0020'; names = new List<string> {"JFK", "ATL", "LAX"}; break; case "2": fileName = "movies.txt"; delimiter = '/'; names = new List<string> { "Tin Men (1987)", "Bacon, Kevin" }; break; //case "3": // fieName = "largeG.zip"; // break; case "quit": return; default: return; } var @in = new In($"Files\\Graphs\\{fileName}"); var lines = !fileName.EndsWith("zip") ? @in.ReadAllLines() : @in.ReadAllLinesFromZip(); var sg = new SymbolDigraph(lines, delimiter); var digraph = sg.G; foreach (var name in names) { Console.WriteLine($"{name}"); if (sg.Contains(name)) { var s = sg.Index(name); foreach (int v in digraph.Adj(s)) { Console.WriteLine($" {sg.Name(v)}"); } } else { Console.WriteLine($"input not contain '{name}'"); } } 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 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(); }
public void Run() { Console.WriteLine("Choose file:"); // Prompt Console.WriteLine("1 - tinyG.txt"); // Prompt Console.WriteLine("2 - mediumG.txt"); // Prompt Console.WriteLine("or quit"); // Prompt var fileNumber = Console.ReadLine(); var fieName = string.Empty; switch (fileNumber) { case "1": fieName = "tinyG.txt"; break; case "2": fieName = "mediumG.txt"; break; case "quit": return; default: return; } var @in = new In($"Files\\Graphs\\{fieName}"); var lines = @in.ReadAllLines(); var lineIterator = 0; var v = 0; var e = 0; var edges = new List<EdgeU>(); foreach (var line in lines) { if (lineIterator == 0) { v = Convert.ToInt32(line); } if (lineIterator == 1) { e = Convert.ToInt32(line); } if (lineIterator > 1) { var lineSplitted = line.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); var ve = Convert.ToInt32(lineSplitted[0]); var we = Convert.ToInt32(lineSplitted[1]); var edge = new EdgeU(ve, we); edges.Add(edge); } lineIterator++; } var graph = new Graph(v, e, edges); Console.WriteLine(graph); 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(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(); }
public void Run() { Console.WriteLine("Choose file:"); // Prompt Console.WriteLine("1 - tinyBTree.txt"); // Prompt Console.WriteLine("or quit"); // Prompt var fileNumber = Console.ReadLine(); var fieName = string.Empty; switch (fileNumber) { case "1": fieName = "tinyBTree.txt"; break; case "quit": return; default: return; } var @in = new In($"Files\\Context\\{fieName}"); var keyValues = @in.ReadAllLines(); //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 bree = new BTree<string,string>(); foreach (var keyValue in keyValues) { var splittedKeyValue = keyValue.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries); var key = splittedKeyValue[0]; var value = splittedKeyValue[1]; bree.Put(key,value); } Console.WriteLine("cs.princeton.edu: " + bree.Get("www.cs.princeton.edu")); Console.WriteLine("hardvardsucks.com: " + bree.Get("www.harvardsucks.com")); Console.WriteLine("simpsons.com: " + bree.Get("www.simpsons.com")); Console.WriteLine("apple.com: " + bree.Get("www.apple.com")); Console.WriteLine("ebay.com: " + bree.Get("www.ebay.com")); Console.WriteLine("dell.com: " + bree.Get("www.dell.com")); Console.WriteLine(); Console.WriteLine("size: " + bree.Size()); Console.WriteLine("height: " + bree.Height()); Console.WriteLine(bree); Console.ReadLine(); }
public void Run() { Console.WriteLine("Choose file:"); // Prompt Console.WriteLine("1 - routes.txt"); // Prompt Console.WriteLine("2 - movies.txt"); // Prompt //Console.WriteLine("3 - largeG.zip"); // Prompt Console.WriteLine("or quit"); // Prompt var fileNumber = Console.ReadLine(); string fileName; char delimiter; string source; List<string> names; switch (fileNumber) { case "1": fileName = "routes.txt"; delimiter = '\u0020'; source = "JFK"; names = new List<string> { "LAS", "DFW", "EWR" }; break; case "2": fileName = "movies.txt"; delimiter = '/'; source = "Bacon, Kevin"; names = new List<string> { "Kidman, Nicole", "Grant, Cary" }; break; //case "3": // fieName = "largeG.zip"; // break; case "quit": return; default: return; } var @in = new In($"Files\\Graphs\\{fileName}"); var lines = !fileName.EndsWith("zip") ? @in.ReadAllLines() : @in.ReadAllLinesFromZip(); var degreesOfSeparation = new DegreesOfSeparation(lines, delimiter, source); Console.WriteLine($"{source}"); foreach (var name in names) { Console.WriteLine($"{name}"); degreesOfSeparation.Find(name); } Console.ReadLine(); }
public void Run() { Console.WriteLine("Choose file:"); // Prompt Console.WriteLine("1 - tinyST.txt"); // Prompt Console.WriteLine("or quit"); // Prompt var fileNumber = Console.ReadLine(); var fieName = string.Empty; switch (fileNumber) { case "1": fieName = "tinyST.txt"; break; case "quit": return; default: return; } var @in = new In($"Files\\Searching\\{fieName}"); var keyValues = @in.ReadAllLines(); //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 redBlackBST = new RedBlackBST<string,string>(); foreach (var keyValue in keyValues) { var splittedKeyValue = keyValue.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); var key = splittedKeyValue[0]; var value = splittedKeyValue[1]; redBlackBST.Put(key,value); } // print results foreach (var item in redBlackBST.Keys()) { Console.WriteLine(redBlackBST.Get(item)); } Console.WriteLine(redBlackBST.Max()); Console.WriteLine(redBlackBST.Min()); 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(); }
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 = "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(); }
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() { 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(); }
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 - 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(); }
public void Run() { Console.WriteLine("Choose file:"); // Prompt Console.WriteLine("1 - tinySET.txt"); // Prompt Console.WriteLine("or quit"); // Prompt var fileNumber = Console.ReadLine(); var fieName = string.Empty; switch (fileNumber) { case "1": fieName = "tinySET.txt"; break; case "quit": return; default: return; } var @in = new In($"Files\\Searching\\{fieName}"); var keys = @in.ReadAllLines(); //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 set = new SET<string>(); foreach (var key in keys) { set.Add(key); } // print results foreach (var item in set) { Console.WriteLine(item); } Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine(set.Contains("www.cs.princeton.edu")); Console.WriteLine(!set.Contains("www.harvardsucks.com")); Console.WriteLine(set.Contains("www.simpsons.com")); Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine(); Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine("ceiling(www.simpsonr.com) = " + set.Ceiling("www.simpsonr.com")); Console.WriteLine("ceiling(www.simpsons.com) = " + set.Ceiling("www.simpsons.com")); Console.WriteLine("ceiling(www.simpsont.com) = " + set.Ceiling("www.simpsont.com")); Console.WriteLine("floor(www.simpsonr.com) = " + set.Floor("www.simpsonr.com")); Console.WriteLine("floor(www.simpsons.com) = " + set.Floor("www.simpsons.com")); Console.WriteLine("floor(www.simpsont.com) = " + set.Floor("www.simpsont.com")); Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine(); Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine(set.Max()); Console.WriteLine(set.Min()); Console.WriteLine(); Console.ReadLine(); }
public void Run() { Console.WriteLine("Choose file:"); // Prompt Console.WriteLine("1 - tinyDG.txt"); // Prompt Console.WriteLine("2 - mediumDG.txt"); // Prompt Console.WriteLine("or quit"); // Prompt var fileNumber = Console.ReadLine(); string fileName; switch (fileNumber) { case "1": fileName = "tinyDG.txt"; break; case "2": fileName = "mediumDG.txt"; break; case "quit": return; default: return; } var @in = new In($"Files\\Graphs\\{fileName}"); var lines = @in.ReadAllLines(); var lineIterator = 0; var v = 0; var e = 0; var edges = new List<EdgeD>(); foreach (var line in lines) { if (lineIterator == 0) { v = Convert.ToInt32(line); } if (lineIterator == 1) { e = Convert.ToInt32(line); } if (lineIterator > 1) { var lineSplitted = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ve = Convert.ToInt32(lineSplitted[0]); var we = Convert.ToInt32(lineSplitted[1]); var edge = new EdgeD(ve, we); edges.Add(edge); } lineIterator++; } var digraph = new Digraph(v, e, edges); Console.WriteLine(digraph); Console.WriteLine("------------------------------------------------------"); const int s = 3; var bfs = new BreadthFirstDirectedPaths(digraph, s); for (var i = 0; i < digraph.V; i++) { if (bfs.HasPathTo(i)) { Console.Write($"{s} to {i} ({bfs.DistTo(i)}): "); foreach (int x in bfs.PathTo(i)) { if (x == s) Console.Write(x); else Console.Write("->" + x); } Console.WriteLine(); } else { Console.Write($"{s} to {i} (-): not connected{Environment.NewLine}"); } } Console.ReadLine(); }
public void Run() { Console.WriteLine("Choose file:"); // Prompt Console.WriteLine("1 - tinyDG.txt"); // Prompt Console.WriteLine("or quit"); // Prompt var fileNumber = Console.ReadLine(); string fileName; switch (fileNumber) { case "1": fileName = "tinyDG.txt"; break; case "quit": return; default: return; } var @in = new In($"Files\\Graphs\\{fileName}"); var lines = @in.ReadAllLines(); var lineIterator = 0; var v = 0; var e = 0; var edges = new List<EdgeD>(); foreach (var line in lines) { if (lineIterator == 0) { v = Convert.ToInt32(line); } if (lineIterator == 1) { e = Convert.ToInt32(line); } if (lineIterator > 1) { var lineSplitted = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ve = Convert.ToInt32(lineSplitted[0]); var we = Convert.ToInt32(lineSplitted[1]); var edge = new EdgeD(ve, we); edges.Add(edge); } lineIterator++; } var digraph = new Digraph(v, e, edges); Console.WriteLine(digraph); Console.WriteLine("------------------------------------------------------"); var bag1 = new Core.Collections.Bag<Integer> { new Integer(1) }; var bag2 = new Core.Collections.Bag<Integer> { new Integer(2) }; var bag3 = new Core.Collections.Bag<Integer> { new Integer(6) }; var listSources = new List<Core.Collections.Bag<Integer>> { bag1, bag2, bag3 }; foreach (var sources in listSources) { foreach (var source in sources) { // multiple-source reachability var dfs = new NonrecursiveDirectedDFS(digraph, source.Value); // print out vertices reachable from sources for (var i = 0; i < digraph.V; i++) { if (dfs.Marked(i)) Console.Write($"{i} "); } Console.WriteLine(); } Console.WriteLine(); Console.WriteLine("---------------------------------------------------------"); } Console.ReadLine(); }
public void Run() { Console.WriteLine("Choose file:"); // Prompt Console.WriteLine("1 - tinyCG.txt"); // Prompt Console.WriteLine("2 - mediumG.txt"); // Prompt Console.WriteLine("or quit"); // Prompt var fileNumber = Console.ReadLine(); var fieName = string.Empty; switch (fileNumber) { case "1": fieName = "tinyCG.txt"; break; case "2": fieName = "mediumG.txt"; break; case "quit": return; default: return; } var @in = new In($"Files\\Graphs\\{fieName}"); var lines = @in.ReadAllLines(); var lineIterator = 0; var v = 0; var e = 0; var edges = new List<EdgeU>(); foreach (var line in lines) { if (lineIterator == 0) { v = Convert.ToInt32(line); } if (lineIterator == 1) { e = Convert.ToInt32(line); } if (lineIterator > 1) { var lineSplitted = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ve = Convert.ToInt32(lineSplitted[0]); var we = Convert.ToInt32(lineSplitted[1]); var edge = new EdgeU(ve, we); edges.Add(edge); } lineIterator++; } var graph = new Graph(v, e, edges); Console.WriteLine(graph); const int s = 0; var dfs1 = new DepthFirstPaths(graph, s); for (var vi = 0; vi < graph.V; vi++) { if (dfs1.HasPathTo(vi)) { Console.Write($"{s} to {vi}: "); foreach (int x in dfs1.PathTo(vi)) { if (x == s) Console.Write(x); else Console.Write($"-{x}"); } Console.WriteLine(); } else { Console.WriteLine($"{s} to {v}: not connected{Environment.NewLine}"); } } //Console.WriteLine("------------------------------------------------"); Console.ReadLine(); }
public void Run() { Console.WriteLine("Choose file:"); // Prompt Console.WriteLine("1 - tinyEWD.txt"); // Prompt Console.WriteLine("2 - mediumEWD.txt"); // Prompt //Console.WriteLine("3 - mediumEWG.txt"); // Prompt Console.WriteLine("or quit"); // Prompt var fileNumber = Console.ReadLine(); string fileName; switch (fileNumber) { case "1": fileName = "tinyEWD.txt"; break; case "2": fileName = "mediumEWD.txt"; break; //case "3": // fileName = "largeEWG.zip"; // break; case "quit": return; default: return; } var @in = new In($"Files\\Graphs\\{fileName}"); var lines = @in.ReadAllLines(); var lineIterator = 0; var v = 0; var e = 0; var edges = new List<DirectedEdge>(); foreach (var line in lines) { if (lineIterator == 0) { v = Convert.ToInt32(line); } if (lineIterator == 1) { e = Convert.ToInt32(line); } if (lineIterator > 1) { var lineSplitted = line.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); var ve = Convert.ToInt32(lineSplitted[0]); var we = Convert.ToInt32(lineSplitted[1]); var weight = Convert.ToDouble(lineSplitted[2], CultureInfo.InvariantCulture); var edge = new DirectedEdge(ve, we, weight); edges.Add(edge); } lineIterator++; } var adjMatrixEdgeWeightedDigraph = new AdjMatrixEdgeWeightedDigraph(v, e, edges); Console.WriteLine(adjMatrixEdgeWeightedDigraph); // run Floyd-Warshall algorithm var spt = new FloydWarshall(adjMatrixEdgeWeightedDigraph); // print all-pairs shortest path distances Console.Write(" "); for (var vv = 0; vv < adjMatrixEdgeWeightedDigraph.V; vv++) { Console.Write($"{vv} "); } Console.WriteLine(); for (var vv = 0; vv < adjMatrixEdgeWeightedDigraph.V; vv++) { Console.Write($"{vv}: "); for (var w = 0; w < adjMatrixEdgeWeightedDigraph.V; w++) { Console.Write(spt.HasPath(vv, w) ? $"{spt.Dist(vv, w):00} " : " Inf "); } Console.WriteLine(); } // print negative cycle if (spt.HasNegativeCycle) { Console.WriteLine("Negative cost cycle:"); foreach (var edge in spt.NegativeCycle()) Console.WriteLine(edge); Console.WriteLine(); } // print all-pairs shortest paths else { for (var vv = 0; vv < adjMatrixEdgeWeightedDigraph.V; vv++) { for (var w = 0; w < adjMatrixEdgeWeightedDigraph.V; w++) { if (spt.HasPath(vv, w)) { Console.Write($"{vv} to {w} {spt.Dist(vv, w):00} "); foreach (var edge in spt.Path(vv, w)) Console.Write($"{edge} "); Console.WriteLine(); } else { Console.Write($"{vv} to {w} no path{Environment.NewLine}"); } } } } Console.ReadLine(); }