aphabetical sorting

Hi,im trying to write a c++ code for aplhabetical sorting....
I succeeded partially...But the code wont work if the number of characters goes beyond 6.

I assign a number for every word in the following way and sort the words by sorting the numbers assigned to the corresponding words.
ex: worddd = 23*27^5 + 14*27^4 + 18*27^3 + 4*27^2 + 4*27 + 4
(w is 23rd aplabet,o is 14th,r is 18 th and d is 4th )
anything beyond 6 characters would exceed the range of int.

Im looking for a better one..Anyone help me...
Last edited on
You can compare std::strings by using relational operators. They're already set up to test for dictionary order.
but it is always a good programming practice for beginners to write the codes with minimum number of predefined functions...So im trying to do so.

thank you....(i was not aware of the function)
Can you tell a better method to do it?
Reinventing the wheel can sometimes be very helpful as a learning exercise, though I don't really think this is the case.

Anyway, if you want to do it in a more low level fashion, you can compare the chars themselves with relational operators. No standard library involved.
You don't need to convert the characters into one big integer. Each individual character is a number so you need to visit every character of both strings and compare them until you get a mismatch.
ya....that is a better idea..thank you.
Topic archived. No new replies allowed.