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.

30th Aug 2020, 10:07 AM
Xtron135
Xtron135 - avatar
12 Respostas
0
definetly a bit longer than python, or its just me being bad at it https://code.sololearn.com/cuFC804HAUSy/?ref=app
30th Aug 2020, 12:25 PM
Rei
Rei - avatar
+ 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
30th Aug 2020, 12:06 PM
Lothar
Lothar - avatar
+ 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
30th Aug 2020, 12:11 PM
Slick
Slick - avatar
+ 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
30th Aug 2020, 10:10 AM
Slick
Slick - avatar
+ 1
yeah man, easily by adding .split() a couple times https://code.sololearn.com/cYvBgoZ9j0iN/?ref=app
30th Aug 2020, 10:54 AM
Slick
Slick - avatar
+ 1
Xtron135 yes, in same code just add .split(" ") to the input. maybe playaround with the output abit to make it readable
30th Aug 2020, 10:54 AM
Rei
Rei - avatar
+ 1
Rei great minds! haha, but for future reference, there's no need to explicitly split at a space since that's the default.
30th Aug 2020, 10:56 AM
Slick
Slick - avatar
+ 1
Slick ah, i get it mixed up with javascript split()
30th Aug 2020, 10:58 AM
Rei
Rei - avatar
+ 1
Rei thanks for the info. U guys r so good. 😅😅
30th Aug 2020, 12:26 PM
Xtron135
Xtron135 - avatar
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"
30th Aug 2020, 10:50 AM
Xtron135
Xtron135 - avatar
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.
30th Aug 2020, 11:39 AM
Xtron135
Xtron135 - avatar
0
c++ ? there is std::sort in <algorithm> you can split the string into vector firstm then use strcmp for string comparison
30th Aug 2020, 11:58 AM
Rei
Rei - avatar