Here's the VB6 code. Hope you can translate this to >> java man
BTW I used the insertion sort method cause its easier and faster when working with large numbers!
VB6 functions:
Mid(string, <starting pos> , <number of characters>
Used to store string from the middle of a string
Val(string)
Used to convert a string to number
Dim <variable> AS <data type>
Declare a variable as data type
Swap a(i),a(j)
Interchange the position of values
len
Count the number of characters in a string
| CODE |
Dim a{len(string)} as Integer
'Take individual numbers to array For i= 1 to len(string) a(i)= mid{string,i,1} next i
'A number Checks numbers before it and it is swapped if it bigger than the other 'So basically to check numbers before we have to start from 2nd value for i = 2 to len (string) For j= 1 to i - 1 If val{a(i)} < val{a(j)} then For k = j to i-1 swap a(i), a(j) next k Exit for End if Next j Next i
'Combine the array into the string for I= 1 to len(strin) string= string+a(i) next i
|
EDIT: OOPs I am sorry, use asc instead of Val, asc turns the character into ascii code
This post has been edited by Swoorup on Sunday, Sep 11 2011, 05:44