0
String Sorting System?
We can do bubble sort to sort int array. Well thats the only sorting system that i know for now. Will bubble sort system work to sort string arrays or char array in alphabetical way? (sorting the strings in alphabetical way, not sorting the letters in a string) If no, is there any sorting system that works well with char and string? Spesifically on c++. Python is also acceptable if not so complex, hehe still learning on python.
12 Answers
0
definetly a bit longer than python, or its just me being bad at it
https://code.sololearn.com/cuFC804HAUSy/?ref=app
+ 8
Slick , i am not able to message you directly, so i put some thoughts in a file:
https://code.sololearn.com/cHWQksOFj7sI/?ref=app
+ 2
Wow, thanks Lothar! I definatley see what you mean. I didnt even think about that. The scripts are small but anything large and Id just be twiddling my thumbs while i waited. Good eye
+ 1
Yes, it sorts characters by ascii value.
In python there are simple functions you can call to get the same effect.
https://code.sololearn.com/cZ6yhZ47S5Cz/?ref=app
+ 1
yeah man, easily by adding .split() a couple times
https://code.sololearn.com/cYvBgoZ9j0iN/?ref=app
+ 1
Xtron135 yes, in same code just add .split(" ") to the input.
maybe playaround with the output abit to make it readable
+ 1
Rei great minds! haha, but for future reference, there's no need to explicitly split at a space since that's the default.
+ 1
Slick ah, i get it mixed up with javascript split()
+ 1
Rei thanks for the info. U guys r so good. đ
đ
0
Slick thanks. I see that works well on numbers and a single string. Will it work to sort multiple string? Specifically a string array?
Eg based on ur code,
"hello" "this" "is" "a" "string"
can it be sorted into this?
"a" "is" "hello" "string" "this"
0
Ok i get it for now.. hmm but still no c++ solution. I wonder if there anything like the auto sort func in c++.
Anyway, thanks guys.
0
c++ ? there is std::sort in <algorithm>
you can split the string into vector firstm then use strcmp for string comparison