/// <summary> /// Demo test for the <c>TextInput</c> data type. The test shows /// the methods' behavior and how to use them. /// </summary> /// <param name="args">Place holder for user arguments</param> public static void MainTest(string[] args) { TextInput StdIn = new TextInput(); Console.Write("Type 3 char, 1 integer, a few strings: "); char[] c = { StdIn.ReadChar(), StdIn.ReadChar(), StdIn.ReadChar() }; int a = StdIn.ReadInt(); string s = StdIn.ReadLine(); Console.WriteLine("3 char: {0}, 1 int: {1}, new line: {2}", new string(c), a, s); Console.Write("Type a string: "); s = StdIn.ReadString(); Console.WriteLine("Your string was: " + s); Console.WriteLine(); Console.Write("Type an int: "); a = StdIn.ReadInt(); Console.WriteLine("Your int was: " + a); Console.WriteLine(); Console.Write("Type a bool: "); bool b = StdIn.ReadBool(); Console.WriteLine("Your bool was: " + b); Console.WriteLine(); Console.Write("Type a double: "); double d = StdIn.ReadDouble(); Console.WriteLine("Your double was: " + d); Console.WriteLine(); Console.WriteLine("Enter a line:"); s = StdIn.ReadLine(); Console.WriteLine("Your line was: " + s); Console.WriteLine(); Console.Write("Type any thing you like, enter Ctrl-Z to finish: "); string[] all = StdIn.ReadAllStrings(); Console.WriteLine("Your remaining input was:"); foreach (var str in all) { Console.Write(str + " "); } Console.WriteLine(); }
public static void MainTest(string[] args) { TextInput StdIn = new TextInput(); Bag <string> bag = new Bag <string>(); while (!StdIn.IsEmpty) { string item = StdIn.ReadString(); bag.Add(item); } Console.WriteLine("Size of bag = " + bag.Count); foreach (string s in bag) { Console.WriteLine(s); } }
public static void MainTest(string[] args) { TextInput StdIn = new TextInput(); string[] a = StdIn.ReadAllStrings(); OrderHelper.Show(a); // shuffle StdRandom.Shuffle(a); // display results again using select Console.WriteLine(); for (int i = 0; i < a.Length; i++) { string ith = (string)Quick.Select(a, i); Console.WriteLine(ith); } }
public static void MainTest(string[] args) { TextInput StdIn = new TextInput(); MinPQ <string> pq = new MinPQ <string>(); while (!StdIn.IsEmpty) { string item = StdIn.ReadString(); if (!item.Equals("-")) { pq.Insert(item); } else if (!pq.IsEmpty) { Console.Write(pq.DelMin() + " "); } } Console.WriteLine("(" + pq.Count + " left on pq)"); }
public static void MainTest(string[] args) { var stack = new Stack <string>(); TextInput StdIn = new TextInput(); while (!StdIn.IsEmpty) { string item = StdIn.ReadString(); if (!item.Equals("-")) { stack.Push(item); } else if (!stack.IsEmpty) { Console.Write(stack.Pop() + " "); } } Console.WriteLine("(" + stack.Size + " left on stack)"); }
public static void MainTest(string[] args) { TextInput StdIn = new TextInput(); BST <string, int> st = new BST <string, int>(); for (int i = 0; !StdIn.IsEmpty; i++) { string key = StdIn.ReadString(); st[key] = i; } foreach (string s in st.Keys()) { Console.WriteLine("{0} {1}", s, st.Get(s)); } Console.WriteLine(); foreach (string s in st.LevelOrder()) { Console.WriteLine(s + " " + st[s]); } }