+ 6
How to sort 10 strings in alphabetical order
I want to write a program a to sort 10 strings in alphabetical order
16 Antworten
+ 7
I want to post a new solution which is std::sort
look at algorithm header file , its fast and standard.
try
std::sort(mystring.begin(),mystring.end());
for a start don't forget to look at algorithm header file.
edit:::
here's the full code (fast , portable , standard , modern solution and in 5 lines) or less
https://code.sololearn.com/cZEPLfKbS8ko/?ref=app
+ 8
Yeah maybe ASCII code. In fact, just getting the character at a given position, they are char variables and you can treat them as integers with the value being their ASCII value.
So 'b'>'a'.
However, 'N'<'b'.
+ 7
Which one should come later?
abba
OR
baa?
This question will help me determine what else you factor in.
+ 7
Then what you should do is sort everything by first character.
You implement a comparison function then use one of the sorting algorithms.
+ 6
#include <algorithm>
+ 4
Well I want it in dictionary order so Abba should be first as we have A first in dictionary and then we have words from A such as Ab then Ac ......
+ 4
How can I do that
+ 4
May be by using ASCII code
+ 4
Sorry I can't understand the Answer because I am very new to programming like few months
+ 4
Ok I'll try and let you know thanks for help buddy 😀
+ 4
Ok, so it will sort the string array in alphabetical order I'll try and let you know my friend
+ 4
Thanks bro I am done with sort function thanks to everyone for help
+ 3
Bro I can't understand what you are saying 😂 what algorithm header file
+ 3
Two steps -
1-Convert into lower case
2-Compare ASCII codes of substring [0] from the lowest to highest
+ 2
temp=input ("enter the strings")
a=list(temp.split())
sorted (a)
print(a)
+ 1
I tell you that you may solve this problem by using sort method in c++ STD directly, but it can't exercise your algorithmic idea. Depending on existing functions, it's not possible. You have to find a way to solve this problem by yourself. This is my attempt to sort 10 strings with insertion sort algorithm for reference only.
https://code.sololearn.com/cwJaNSXR0VaZ/?ref=app