Created
March 11, 2022 15:48
-
-
Save t3knoid/37f2947341bb2e37f6abedca8235ba76 to your computer and use it in GitHub Desktop.
Use this comparer to sort a list of bytes,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// | |
/// Usage listBytes.Sort(new ByteListComparer()); | |
/// | |
public class ByteListComparer : IComparer<IList<byte>> | |
{ | |
public int Compare(IList<byte> x, IList<byte> y) | |
{ | |
int result; | |
for (int index = 0; index < Math.Min(x.Count, y.Count); index++) | |
{ | |
result = x[index].CompareTo(y[index]); | |
if (result != 0) return result; | |
} | |
return x.Count.CompareTo(y.Count); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment