+ 6

How to sort 10 strings in alphabetical order

I want to write a program a to sort 10 strings in alphabetical order

17th May 2019, 1:21 PM
Arslan Iftikhar
Arslan Iftikhar - avatar
16 ответов
+ 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
17th May 2019, 2:27 PM
‎وائل عبد الحق‎
‎وائل عبد الحق‎ - avatar
+ 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'.
17th May 2019, 1:58 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 7
Which one should come later? abba OR baa? This question will help me determine what else you factor in.
17th May 2019, 1:40 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 7
Then what you should do is sort everything by first character. You implement a comparison function then use one of the sorting algorithms.
17th May 2019, 1:54 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 6
#include <algorithm>
17th May 2019, 2:36 PM
‎وائل عبد الحق‎
‎وائل عبد الحق‎ - avatar
+ 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 ......
17th May 2019, 1:51 PM
Arslan Iftikhar
Arslan Iftikhar - avatar
+ 4
How can I do that
17th May 2019, 1:55 PM
Arslan Iftikhar
Arslan Iftikhar - avatar
+ 4
May be by using ASCII code
17th May 2019, 1:55 PM
Arslan Iftikhar
Arslan Iftikhar - avatar
+ 4
Sorry I can't understand the Answer because I am very new to programming like few months
17th May 2019, 1:57 PM
Arslan Iftikhar
Arslan Iftikhar - avatar
+ 4
Ok I'll try and let you know thanks for help buddy 😀
17th May 2019, 1:59 PM
Arslan Iftikhar
Arslan Iftikhar - avatar
+ 4
Ok, so it will sort the string array in alphabetical order I'll try and let you know my friend
17th May 2019, 2:36 PM
Arslan Iftikhar
Arslan Iftikhar - avatar
+ 4
Thanks bro I am done with sort function thanks to everyone for help
17th May 2019, 3:00 PM
Arslan Iftikhar
Arslan Iftikhar - avatar
+ 3
Bro I can't understand what you are saying 😂 what algorithm header file
17th May 2019, 2:35 PM
Arslan Iftikhar
Arslan Iftikhar - avatar
+ 3
Two steps - 1-Convert into lower case 2-Compare ASCII codes of substring [0] from the lowest to highest
18th May 2019, 6:04 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 2
temp=input ("enter the strings") a=list(temp.split()) sorted (a) print(a)
17th May 2019, 4:56 PM
$undeep Kumar
$undeep Kumar - avatar
+ 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
17th May 2019, 5:05 PM
Jesscar🇨🇳🇭🇰
Jesscar🇨🇳🇭🇰 - avatar