c# - Somewhat complex list sorting -
I have several objects with 3 numerical properties: "high", "low" and "tibrecker" Should be solved: If an object is less than the height of any other object, then it appears before the list. Similarly, if the height of an object is at least the other, then it appears later in the list. But in this case there are contradictory categories on two objects (such as someone's high object is between low and high of second object), the property of the tiebraker is considered in which the object with the upper tibrere value is placed first in the list.
I am working with C # in particular, but I think the language of thoughts here is very ignorant as any kind of code should be welcomed.
In addition, I is worked on it myself. I have a nested for-loop that is not working for me yet, I leave some code, but I'm on my phone and it works as a house, besides it, maybe it's fun for you and you have some I do not even need my ugly code in the way. Do you believe that a & lt; B (because they overlap and -10 & lt; 1) B & lt; C (because they overlap and 1 & lt; 3) but A & gt; C (because they do not overlap and 5> 4) If you are, you can define a custom for your Update and there is such an implementation here. It can be used as: I used the minimum < = Tie & lt; = Max ? You do not say this in your question, and if you do not, the sort order is not properly defined because it is not. For example, write your limits as
[min, tie, max] :
A: [5, -10, 6] b: [0 , 1, 10] C: [2, 3, 4]
range class, and do any of it Can pass C #.
The public profile range range < T & gt; Where T: Ikkectable & lt; T & gt;, IComperbal & lt; T & gt; {Read t minutes only; Only readable T max; T-Tie for reading only; Is not readable only; Public stable range & lt; T & gt; Empty = new range & lt; T & gt; (); Public static ICMPear & lieutenant; Rangeview & lt; T & gt; & Gt; CreateSortingComparer () Return to New Range WideTyPaire ()) Public Range Wave (T Start, T-Tie, T &) {// Unique Start and Lieutenant; = Tie & lieutenant; = End of Comparison = Thullarar & lt; T & gt; Default; If (comparer.Compare (start, end)> 0) // if start> End {Except new logic; Apparax exception ("Start and end reversal"); } And if compare. (Compare (start, tie)> 0) {New Argument of Upgrade Expression ("Tie is less than Beginning"); } And if compare (Comparre (Tie, End)> 0) {Except new logic unchanged exception ("Tie is greater than end"); } Else {this.min = start; This.max = end; This.tie = tie; } This.isNonEmpty = True; } Receive public t {{return minute; }} Get Public T Maximum {Receive {Max. Max; }} Public tie {get {return tie; }} Public child iacquity {get {return! Is non-empty; }} Public Class Range Wide Comparrier: iCompair & lt; Rangewity & lt; T & gt; & Gt; {#region IComparer & lt; Rangewity & lt; T & gt; & Gt; Member Public Int Comparison (Rangwit & lt; T & gt; x, Range Wifi & lt; T & gt; y) {// Return x - y if (x.IsEmpty) {If (y.IsEmpty) 0; Other return -1; } And if (y.IsEmpty) {return1; } Var comparer = Bulanar & lt; T & gt; Default; If (comparator comparison (y.min, x.max)> 0) return -1; And if (comparative .computer (X.Man, Y.Max)> gt; 1) returns 1; Compare the return. Comparison (X. Tie, Y. Tie); } #endregion} Public override string ToString () {if (isEmpty) "empty" return; Stringbuilder s = new stringbiller (); S.Append ('[']; If (minimum! = Null) {s.Append (Min. ToString ()); } S.Append (","); If (tie! = Null) {s.Append (tie.tostring ()); } S.Append (","); If (max! = Null) {s.Append (max. ToString ()); } S.Append (')'); Return s Toasting (); }}
var sortedRanges = ranges.OrderBy (x => x, RangeWithTie & lt; Double> CreateSortingComparer)) toArray () .;
IComparer
[- 1,0,1] and
[- 2 , 0,1] do the same comparison but are not equal.
Comments
Post a Comment