public void Delete_Performance_Test() { int size = 9000; var st = new SequentialSearchST<int, string>(); for (int i = 0; i < size; i++) { st.Put(i, i.ToString()); } using (new PerformanceWatch(new CDriveLocationLogger(), "recursive")) { for (int i = 0; i < size; i++) { st.Delete_Recursive(i); } } var st2 = new SequentialSearchST<int, string>(); for (int i = 0; i < size; i++) { st2.Put(i, i.ToString()); } using (new PerformanceWatch(new CDriveLocationLogger(), "non recursive")) { for (int i = 0; i < size; i++) { st2.Delete(i); } } }
public void Delete_Olny_One_Node_List_Test() { var st = new SequentialSearchST<string, string>(); st.Put("a", "0"); st.Delete("a"); Assert.AreEqual(0, st.Size()); }
public void SequentialTest() { SequentialSearchST <string, int> st = new SequentialSearchST <string, int>(); for (int i = 0; i < v.Length; i++) { st.Put(k[i], v[i]); } st.DisPlay(); st.Delete("b"); st.DisPlay(); }
static void Main(string[] args) { ST <string, string> st; st = new SequentialSearchST <string, string>(); st.Put("a", "1"); st.Put("b", "2"); int size = st.Size(); st.Delete("a"); size = st.Size(); SortedST <string, string> sortedSt; sortedSt = new BST <string, string>(); sortedSt.Put("r", "1"); sortedSt.Put("b", "2"); sortedSt.Put("h", "3"); sortedSt.Put("t", "4"); sortedSt.Delete("b"); st = new SeparateChainingHashST <string, string>(); st.Put("f", "1"); st.Put("a", "3"); st.Put("d", "4"); st.Put("h", "9"); st.Put("k", "8"); var v = st.Get("h"); st = new LinearProbingHashST <string, string>(); st.Put("f", "1"); st.Put("a", "3"); st.Put("d", "4"); st.Put("h", "9"); st.Put("u", "8"); v = st.Get("u"); Console.ReadKey(); }
public void SequentialSearchSTTest1() { // testing Get/Put semantics SequentialSearchST <string, int> st = new SequentialSearchST <string, int>(); Assert.IsTrue(st.IsEmpty); // making sure we can delete all from ST st.Put("asd", 355); st.Put("dsd", 25); st.Put("esd", 15); st.Delete("esd"); st.Delete("dsd"); st.Delete("asd"); Assert.IsTrue(st.IsEmpty); string[] keys = { "to", "be", "or", "not", "to", "be", "is", "quest" }; for (int i = 0; i < keys.Length; i++) { st.Put(keys[i], i); } Assert.IsTrue(!(st.IsEmpty) && (st.Count == 6)); string key = "not"; Assert.IsTrue(st.Contains(key)); st.Delete(key); Assert.IsFalse(st.Contains(key)); Assert.IsNull(st.Get(key)); object value = st.Get("is"); Assert.AreEqual(6, value); value = st.Get("world"); Assert.IsNull(value); int dummy = (int)st.Get("hello"); // generate null exception }
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 st = new SequentialSearchST <string, string>(); foreach (var keyValue in keyValues) { var splittedKeyValue = keyValue.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var key = splittedKeyValue[0]; var value = splittedKeyValue[1]; st.Put(key, value); } // print results foreach (var item in st.Keys()) { Console.WriteLine(st.Get(item)); } Console.ReadLine(); }
static void Main(string[] args) { // 官方实现见:https://algs4.cs.princeton.edu/31elementary/SequentialSearchST.java.html var input = "S E A R C H E X A M P L E".Split(' '); var st = new SequentialSearchST <string, int>(); for (var i = 0; i < input.Length; i++) { st.Put(input[i], i); } foreach (var s in st.Keys()) { Console.WriteLine(s + " " + st.Get(s)); } }
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 st = new SequentialSearchST<string,string>(); foreach (var keyValue in keyValues) { var splittedKeyValue = keyValue.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); var key = splittedKeyValue[0]; var value = splittedKeyValue[1]; st.Put(key,value); } // print results foreach (var item in st.Keys()) { Console.WriteLine(st.Get(item)); } Console.ReadLine(); }
public void TestSequentialSearchST() { SequentialSearchST<string, int> st = new SequentialSearchST<string, int>(); int amounts = 20; string[] strs = new string[amounts]; Random rand = new Random(); for (int i = 0; i < amounts; i++) { strs[i] = Convert.ToChar(rand.Next(97, 122)).ToString(); st.Put(strs[i], i); } StringBuilder sb0 = new StringBuilder(); foreach (var str in strs) sb0.Append(str + " "); Debug.WriteLine(sb0.ToString()); StringBuilder sb = new StringBuilder(); foreach (var item in st.Keys()) sb.Append(st.Get(item) + " "); Debug.WriteLine(sb.ToString()); Assert.AreEqual(strs.Distinct().Count(), st.Keys().Count()); }
private SequentialSearchST<string, int?> CreateSTWithNullableValueType() { var st = new SequentialSearchST<string, int?>(); st.Put("a", 0); st.Put("b", 1); st.Put("c", 2); return st; }
private SequentialSearchST<string, string> CreateST() { var st = new SequentialSearchST<string, string>(); st.Put("a", "0"); st.Put("b", "1"); st.Put("c", "2"); return st; }
public GraphBase(int v) { #region node char to int mapping NodeFromCharToIntMapping = new SequentialSearchST<char, int?>(); NodeFromCharToIntMapping.Put('A', 0); NodeFromCharToIntMapping.Put('B', 1); NodeFromCharToIntMapping.Put('C', 2); NodeFromCharToIntMapping.Put('D', 3); NodeFromCharToIntMapping.Put('E', 4); NodeFromCharToIntMapping.Put('F', 5); NodeFromCharToIntMapping.Put('G', 6); NodeFromCharToIntMapping.Put('H', 7); NodeFromCharToIntMapping.Put('I', 8); NodeFromCharToIntMapping.Put('J', 9); NodeFromCharToIntMapping.Put('K', 10); NodeFromCharToIntMapping.Put('L', 11); #endregion _V = v; _E = 0; Al = new LinkedList<Edge>[v]; for (var i = 0; i < v; i++) { Al[i] = new LinkedList<Edge>(); } }