-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sorting string's characters according to their ASCII values #363
base: master
Are you sure you want to change the base?
Conversation
Hello @ChetanKarwa, great to see you managed to build stdlib and get your new function working. However, I am not totally convinced by the purpose of this function. The more common usage of a sort function would be to sort a list of strings (like the one in development in #311), say to output a sorted list of labels. Do you have some usage cases that motivate a character sort function? |
I implemented this because I've seen other languages supporting the sorting of a character array. |
@wclodius2 Is your implementation related to this PR? |
No, it isn't. My sort is of an array of elements of the |
I renamed this PR to avoid confusion with #408 |
What could be done is to provide the O(n) sorting algorithm of @ChetanKarwa as a specialization in #408 when the input is an array of The only usage I can think of currently is to find the median letter (and maybe the mode) in a character sequence. |
Also, consider that this implementation is likely to fail for non-ASCII input: print *, sort("Ångström")
! Fortran runtime error: Index '195' of dimension 1 of array 'count' above upper bound of 128 |
I have implemented a sort function for a string. This function sorts the string's characters according to their ASCII values.
Eg:
string - "This is to be sorted"
sorted string - " Tbdeehiioorssstt"