Beispiel #1
0
        private static KeyValueLengthUpTo50[] getKthValueNumericLengthUpTo50(string[] numbers, int key)
        {
            int length = numbers.Length;

            var kthValues = new KeyValueLengthUpTo50[length];

            for (int i = 0; i < length; i++)
            {
                kthValues[i] = new KeyValueLengthUpTo50(numbers[i].Split(' ')[key - 1]);
            }

            return(kthValues);
        }
Beispiel #2
0
        public int Compare(object o1, object o2)
        {
            KeyValueLengthUpTo50 p1 = o1 as KeyValueLengthUpTo50;
            KeyValueLengthUpTo50 p2 = o2 as KeyValueLengthUpTo50;

            var firstString  = removeLeadingZeros(p1.value);
            var secondString = removeLeadingZeros(p2.value);

            var length1 = firstString.Length;
            var length2 = secondString.Length;

            var lengthEqual = length1 == length2;
            int compare     = -1;

            if (!lengthEqual)
            {
                compare = length1 < length2 ? -1 : 1;
            }
            else
            {
                int index = 0;

                while (index < length1)
                {
                    var first  = firstString[index];
                    var second = secondString[index];

                    var difference = first - second;
                    if (difference == 0)
                    {
                        index++;
                    }
                    else
                    {
                        compare = difference < 0 ? -1 : 1;
                        break;
                    }
                }
            }

            return(compare);
        }