algorithm - Create a List of string in ascending Order in lexicographically order -


i want generate algorithm in want next string in lexicographically order.

suppose want generate list of length 26

['a','b'....'z'] 

now suppose want generate list of length 260

['a0','a1','a2'...'a9','b1'....'z0'....'z9'] 

this type of algorithm have max-limit. don't want such type of limitations. may 10000 or 1 millions.

requirement

algorithm should work in such way string passed argument generate it. , should produce next string in lexicographically order. , not want use timestamp (1503314045645)

thanks

what using base 36 formatted integers? looks in java:

string next(string prev) {   if(prev==null) {     return "0";   }   return integer.tostring(integer.parseint(prev, 36), 36); } 

actually it's better if you use simple integer storing value, , increase every time need next value , format integer using base 36 string:

integer.tostring(++value, 36); 

in solution numbers before letters in output, following tokens: a7,a8,a9,aa,ab, ... ax,ay,az,b0,b1 ... zx,zy,zz,100,101

if want letters first or want specific order or characters, use solution behind matt timmermans' link.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -