After
I have a Su A quick look at the chi function was not so encouraging, so I wondered if someone knows a function I can use Edit: This is a local temporary list so I know that it is correct Will be resolved in a way Edit: BinarySearch looks almost right but in my case I do not have an item to compare. I use the solution of John Skeet and ignoring one argument, but I'm not sure that I can always trust him on the same argument. New Edit: I will skip extra binary searches below because they Useful for others, and this is the last option that I think is exactly what you want. Your representative should return a positive number if the item which is visible is less than "specified", a negative number if it is more than "specified", and 0 if it is correct. Older Editing: I will leave the original answer below, but here are two other options. First projection takes from the source data for a key type, and specifies the key to find. The comparison is just that the key is used by default for the type: Compared to one item in the second list, we are searching for it. The code is almost exactly the same, of course - it's just the comparison changes: These two are unwanted, but at least compile :) Basic Answer: You can In fact, the code is too low I can paste it too (without comment, of course). Then you can do something like this: There is also from the list, that is, I do not have any particular item Looking to search for an item, but for an item given a satisfactory condition, by looking at an item in the list, I can test which of the 4 conditions are correct:
public static int BinarySearchForMatch & LT; T & gt; (The IList & lt; t & gt; list; function of & lt; t, integer & gt; comparer) {int min = 0; Int max = list.Count-1; While (minimum & lt; = max) {int mid = (min + max) / 2; Int compare = comparative (list [middle]); If (comparison == 0) {return median; } If (comparison> <0) {min = mid + 1; } And {max = mid 1; }} Return ~ minute; }
public static int BinarySearchBy & lt; TSource, TKey & gt; (The IList & lt; TSource & gt; list & lt; TSource, TKey & gt; projection, TKey key); {int min = 0; Int max = list.Count-1; While (minimum & lt; = max) {int mid = (min + max) / 2; Vaccine midke = projection (list [middle]); Int Comparison = Lollar & lt; Vaccines & gt; Default. Compre (midke, key); If (comparison == 0) {return median; } If (comparison> <0) {min = mid + 1; } And {max = mid 1; }} Return ~ minute; }
public static int BinarySearchBy & lt; TSource, TKey & gt; (The IList & lt; TSource & gt; list & lt; TSource, TKey, et; GTI; comparison; key of the vaccine; {int min = 0; Int max = list.Count-1; While (minimum & lt; = max) {int mid = (min + max) / 2; Int comparison = comparative (list [middle], key); If (comparison == 0) {return median; } If (comparison> <0) {min = mid + 1; } And {max = mid 1; }} Return ~ minute; }
list & lt; T & gt; Use > A
IComparer & lt; T & gt; Binary search with
. You do not have to IComparer & lt write your own implementation, T & gt; - Compare a
& lt to
; I found on T & gt; which creates a IComparer & lt; T & gt; This representative spots only the first three situations, but binary search will do the last one from the rest.
Public Sealbord Comparison Component < T & gt; : ICompair & lt; T & gt; {Comparison only & lt; T & gt; Comparison; Public Compass Commander (comparison>
var comparer = new comparison compller & lt; Person & gt; ((P1, p2) => p1.id .CompareTo (p2.id)); Int Index = List. Binary search (employee, talanar);
Projection Compacier
in MiscUtil, you may be interested in it - you just specify the launch, such as OrderBy
With LINQ - but it really depends on the case of your use.
Comments
Post a Comment