private void Propagate(Track TrackToPropagate) { foreach (Arc A in TrackToPropagate.EndNode.OutgoingArcs) { if (A.Passable && A.EndNode.Passable) { Track Successor = new Track(TrackToPropagate, A); int PosNF = _Closed.IndexOf(Successor, SameNodesReached); int PosNO = _Open.IndexOf(Successor, SameNodesReached); if (PosNF > 0 && Successor.Cost >= ((Track)_Closed[PosNF]).Cost) { continue; } if (PosNO > 0 && Successor.Cost >= ((Track)_Open[PosNO]).Cost) { continue; } if (PosNF > 0) { _Closed.RemoveAt(PosNF); } if (PosNO > 0) { _Open.RemoveAt(PosNO); } _Open.Add(Successor); } } }
private void RefreshImages() { Image selected = null; if (dataGridView1.SelectedRows.Count == 1) { int index = dataGridView1.SelectedRows[0].Index; selected = images[index]; } var column = dataGridView1.SortedColumn; var order = dataGridView1.SortOrder; images.ResetItems(db.imagesDict.Values); if (selected != null) { int index = images.IndexOf(selected); if (index != -1) { dataGridView1.Rows[index].Selected = true; } } }
/// <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(); }