public void Sort(SortableList sortableList) { ISortStrategy sortingStrategy = efficientSortingStrategyFinder.GetEfficientStrategy(sortableList); sortableList.SortStrategy = sortingStrategy; sortableList.Sort(); }
public void Should_Sort_Using_Shell_Sort() { // Arrange var records = new SortableList(); records.SetSortingStrategy(new ShellSort()); records.Add("Clara"); records.Add("Bella"); records.Add("Abigail"); Assert.IsTrue(records.List[0] == "Clara"); // Act records.Sort(); // Assert Assert.IsTrue(records.List[0] == "Abigail"); Assert.IsTrue(records.List[1] == "Bella"); Assert.IsTrue(records.List[2] == "Clara"); }
public void Should_Sort_Using_Quick_Sort() { // Arrange var records = new SortableList(); records.SetSortingStrategy(new QuickSort()); records.Add("C"); records.Add("B"); records.Add("A"); Assert.IsTrue(records.List[0] == "C"); // Act records.Sort(); // Assert Assert.IsTrue(records.List[0] == "A"); Assert.IsTrue(records.List[1] == "B"); Assert.IsTrue(records.List[2] == "C"); }
public Controls_PageView(string PageName) { XmlUtil x_util = new XmlUtil(); Util util = new Util(); //get page image Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID]; PageImage.ImageUrl = util.GetAppPageImage(State, State["PageViewAppID"].ToString(), PageName); PageImage.ID = PageName + "_PageImage"; PageImage.Attributes.Add("onclick", "goToPage('" + PageName + "');"); PageImage.Attributes.Add("onmouseover", "this.style.cursor='pointer';"); PageImage.Attributes.Add("onmouseout", "this.style.cursor='arrow';"); if (State["UseFullPageImage"] != null) { PageImage.Width = 320; PageImage.Height = 460; } //get page fields XmlDocument doc = x_util.GetStagingAppXml(State); RadTreeNode PageRoot = new RadTreeNode(PageName); PageRoot.CssClass = "RadTreeView"; PageRoot.ImageUrl = "../images/ascx.gif"; PageRoot.Category = "page"; PageRoot.Font.Size = FontUnit.Point(12); OnePageView.Nodes.Add(PageRoot); //do all fields XmlNode page = doc.SelectSingleNode("//pages/page/name[. ='" + PageName + "']").ParentNode; XmlNode fields = page.SelectSingleNode("fields"); if (fields != null) { //sort fields first SortedList list = new SortedList(); SortableList<StoryBoardField> nameList = new SortableList<StoryBoardField>(); foreach (XmlNode child in fields.ChildNodes) { Hashtable dict = new Hashtable(); dict["field_type"] = child.Name; XmlNode id_node = child.SelectSingleNode("id"); dict["id"] = id_node; string input_field = id_node.InnerText.Trim(); if (child.SelectSingleNode("left") != null) dict["left"] = child.SelectSingleNode("left").InnerText; else dict["left"] = "0"; if (child.SelectSingleNode("top") != null) dict["top"] = child.SelectSingleNode("top").InnerText; else dict["top"] = "0"; dict["width"] = child.SelectSingleNode("width").InnerText; dict["height"] = child.SelectSingleNode("height").InnerText; string field_type = dict["field_type"].ToString(); if (field_type == "button" || field_type == "image_button" || field_type == "table" || field_type == "switch") { if(child.SelectSingleNode("submit") != null) dict["submit"] = child.SelectSingleNode("submit").InnerText; } if (field_type == "table" ) { XmlNodeList sub_fields = child.SelectNodes("table_fields/table_field/name"); ArrayList table_list = new ArrayList(); foreach (XmlNode sub_field in sub_fields) { table_list.Add(sub_field.InnerText); } dict["sub_fields"] = table_list; } else if (field_type == "picker") { XmlNodeList sub_fields = child.SelectNodes("picker_fields/picker_field/name"); ArrayList picker_list = new ArrayList(); foreach (XmlNode sub_field in sub_fields) { picker_list.Add(sub_field.InnerText); } dict["sub_fields"] = picker_list; } list[input_field] = dict; nameList.Add(new StoryBoardField(id_node.InnerText.Trim(), Convert.ToInt32(dict["top"].ToString()), Convert.ToInt32(dict["left"].ToString()))); } nameList.Sort("Top", true); foreach (StoryBoardField input_field in nameList) { Hashtable dict = (Hashtable)list[input_field.FieldName]; string field_type = dict["field_type"].ToString(); RadTreeNode field_node = util.CreateFieldNode(PageRoot, input_field.FieldName, field_type); field_node.Value = "left:" + dict["left"].ToString() + ";top:" + dict["top"].ToString() + ";width:" + dict["width"].ToString() + ";height:" + dict["height"].ToString() ; if (dict["submit"] != null && dict["submit"].ToString().Length > 0 && dict["submit"].ToString() != ";") { field_node.BackColor = Color.PeachPuff; string[] submit = dict["submit"].ToString().Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); string target_page_name = null; //this code is compatible with both old and new syntax if (submit[0].StartsWith("post") && (submit[0].Contains("response_page:") || submit[0].Contains("response_page~"))) { target_page_name = submit[0].Substring(19); field_node.Value += ";next_page:" + target_page_name; } else if (submit[0].StartsWith("next_page")) { if (submit[0].Contains("next_page:page~")) target_page_name = submit[0].Substring(15); else target_page_name = submit[0].Substring(10); field_node.Value += ";next_page:" + target_page_name; } } if (field_type == "table" || field_type == "picker") { ArrayList sub_field_list = (ArrayList)dict["sub_fields"]; foreach (string sub_field_name in sub_field_list) { RadTreeNode sub_field_node = util.CreateFieldNode(field_node, sub_field_name, field_type); } } } } OnePageView.ExpandAllNodes(); OnePageView.OnClientMouseOver = "onPageViewMouseOver"; OnePageView.OnClientMouseOut = "onPageViewMouseOut"; }
/// <summary> /// Entry point for the SortableList use case. /// </summary> public static void Main() { try { Console.WriteLine("You create a new SortableList."); SortableList SL = new SortableList(); Console.Write("You set the KeepSorted property to false and you fill it with the strings X, B, A, D: "); SL.KeepSorted = false; SL.Add("X"); SL.Add("B"); SL.Add("A"); SL.Add("D"); Console.WriteLine(SL); Console.Write("You can insert or set elements where you want since KeepSorted==false. Let's set 'C' to index 4: "); SL[3] = "C"; Console.WriteLine(SL); Console.Write("You decide to sort the list: "); SL.Sort(); Console.WriteLine(SL); Console.Write("You now set the KeepSorted property to true and add some new strings: "); SL.KeepSorted = true; SL.Add("J"); SL.Add("E"); SL.Add("E"); SL.Add("B"); SL.Add("X"); SL.Add("E"); SL.Add("E"); Console.WriteLine(SL); Console.WriteLine("'E' is found at index " + SL.IndexOf("E").ToString()); Console.WriteLine("Is the list containing an 'X' value ?: " + SL.Contains("X").ToString()); Console.WriteLine("Is the list containing an 'M' value ?: " + SL.Contains("M").ToString()); Console.Write("You limit the number of occurrences of 'E' to 2: "); SL.LimitNbOccurrences("E", 2); Console.WriteLine(SL); Console.Write("After all you do not want any duplicates: "); SL.RemoveDuplicates(); Console.WriteLine(SL); Console.Write("You set the AddDuplicates property to false and try to add J and E again: "); SL.AddDuplicates = false; SL.Add("J"); SL.Add("E"); Console.WriteLine(SL); Console.WriteLine("Now you create another SortableList but this time you give it an IComparer class which is the anti-alphabetical order."); SL = new SortableList(new AntiAlphabeticalComparer()); Console.Write("You fill the list by adding a range of vowels in alphabetical order. Result: "); string[] Vowels = new string[] { "A", "E", "I", "O", "U" }; SL.AddRange(Vowels); Console.WriteLine(SL); Console.Write("Serialize and Deserialize: "); Stream StreamWrite = File.Create("SortableListSaved.bin"); BinaryFormatter BinaryWrite = new BinaryFormatter(); BinaryWrite.Serialize(StreamWrite, SL); StreamWrite.Close(); Stream StreamRead = File.OpenRead("SortableListSaved.bin"); BinaryFormatter BinaryRead = new BinaryFormatter(); SortableList SL2 = (SortableList)BinaryRead.Deserialize(StreamRead); StreamRead.Close(); Console.WriteLine(SL2); } catch (Exception e) { Console.Write("Error :\n\n" + e.ToString()); } Console.ReadLine(); }
static void _callerQ_Load_Notify(object sender, EventArgs e) { SortableList<CallRecord> overdueItems = new SortableList<CallRecord>(); foreach (CallRecord record in Settings.Default.Queue) { if (record.NotifyDate < DateTime.Now.AddMinutes(2) && !record.WasNotified && record.IsActive) { overdueItems.Add(record); } } if (overdueItems.Count > 0) { overdueItems.Sort("NotifyDate", System.ComponentModel.ListSortDirection.Ascending); foreach (CallRecord record in overdueItems) { using (Notifier notifier = new Notifier()) { notifier.ShowDialog(record); } } } Settings.Save(); SetNotification(); }