I am facing a strange problem while sorting a list of strings with integer values. However some values could be prefixed with some characters.
e.g.
// B1, 5, 50, A10, 7, 72, B3, A1, A2
There are basically page numbers and should be sorted like:
// A1, A2, A10, B1, B3, 5, 7, 50, 72
But if I use default string sorting then these will be sorted like
// A1, A10, A2, B1, B3, 5, 50, 7, 72
Any solution for this in C#?
Convert each element in the String array obtained in the previous step into an integer and store in into the integer array. The sort() method of the Arrays class accepts an array, sorts the contents of it in ascending order. Sort the integer array using this method.
Integer sorting algorithms including pigeonhole sort, counting sort, and radix sort are widely used and practical. Other integer sorting algorithms with smaller worst-case time bounds are not believed to be practical for computer architectures with 64 or fewer bits per word.
Sort String in Java String in Java is immutable. There is no direct method to sort a string in Java. You can use Arrays, which has a method CharArray() that will create a char input string and using another method (Arrays. sort(char c[]) , we can easily sort.
You're looking for the Alphanum algorithm. Fortunately for you, a number of implementations exist already. See here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With