Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sorting alphabeticly
#1
Is there any command that could sort alphabeticly
his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
Reply
#2
'<' and '>'


im pretty sure it works like:

"ape" < "cow"

"Ape" < "ape"

"Cow" < "ape"


i think it goes by ascii values, and i think the capital letters come first, then the small, all in alphabetical order, left-most smallest, e.g.


A, B, C... X, Y, Z .. a, b, c... x, y, z.

It compares down the line, also, e.g.

"Ape" < "Aps"
"Ape" > "Apa"


hope this helps u
Reply
#3
you wouldnt mind showing me an example of a alpha sorter if you have one handy
his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
Reply
#4
mmm you wouldnt mind giving me an example (showing code) of what you need this for, would you?
Reply
#5
Code:
CLS
DEFINT A-Z
CONST false = 0
CONST true = NOT false
INPUT "how many strings to sort? "; num
DIM str(1 TO num)  AS STRING

'get strings
FOR i = 1 TO num STEP 1
PRINT "Please input string #"; i; " ";
INPUT str(i)
NEXT i

'sort strings
DO
  notsort = false
  FOR i = 1 TO num - 1 STEP 1
   IF str(i) > str(i + 1) THEN
    SWAP str(i), str(i + 1)
    notsort = true
   END IF
  NEXT i
LOOP WHILE notsort

'list strings
FOR i = 1 TO num STEP 1
  PRINT str(i)
NEXT i
Reply
#6
As Cha0s pointed out,

Apollo < Zeus < apollo

Which complicates things considerablly if you want to sort and preserve case. If you want to disregard case, then the following modification to my previous code will suffice:


Code:
CLS
DEFINT A-Z
CONST false = 0
CONST true = NOT false
INPUT "how many strings to sort? "; num
DIM str(1 TO num)  AS STRING

'get strings
FOR i = 1 TO num STEP 1
PRINT "Please input string #"; i; " ";
INPUT str(i)
NEXT i

'sort strings
DO
  notsort = false
  FOR i = 1 TO num - 1 STEP 1
   IF LCASE$(str(i)) > LCASE$(str(i + 1)) THEN
    SWAP str(i), str(i + 1)
    notsort = true
   END IF
  NEXT i
LOOP WHILE notsort

'list strings
FOR i = 1 TO num STEP 1
  PRINT str(i)
NEXT i

However, if you want to do a dictionary sort (letter caps length) it will require a bit more...However, knowing that strings can be compared, and how to force the comparison on upper or lower case should be enough to get you going.
Reply
#7
Nice work, Mango. You certainly gave him enough to get going.

BTW, Pyrokid, numbers in the strings will sort before alphabetics. And certain special characters will sort before numbers. Take a look at an ASCII chart.
*****
Reply
#8
lol sorry. i was to tired to think of a way to do it the other night but then i tried it again when i was more awake

heres what i got:

Code:
dim word$(6)
word$(1)="Cat"
word$(2)="Zonker"
word$(3)="Puma"
word$(4)="Articat"
word$(5)="Aardvark"


for i = 1 to 5
    for c=1 to 5
        if c=i then c=c+1
        if word$(i)<word$(c) then swap word$(i),word$(c)
    next
next

for i =1 to 5
    print word$(i)
next
sleep
his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
Reply
#9
Nice, Pyro --- and it works, too.

I think your sort algo is called a Shell Sort.
*****
Reply
#10
Shell sort? looks like a bubble sort to me, I think this is a fast as a bubble sort can get:

Code:
const count = 1000

dim names(count) as string

randomize timer

' fill list with random strings
for i = 0 to count-1
    l = fix(rnd * 12) + 4
    n$ = ""
    for j = 1 to l
        if fix(rnd * 2) then
            n$ = n$ + chr$(65 + fix(rnd * 26))
        else
            n$ = n$ + chr$(97 + fix(rnd * 26))
        end if
    next j
    names(i) = n$
next i

' sort
for i = 0 to count-2
    for j = i+1 to count-1
        if names(i) > names(j) then swap names(i), names(j)
    next j
next i

' check
for i = 0 to count-2
    if names(i) > names(i+1) then exit for
next i

if i < (count-1) then
    print "sort error"
else
    print "sorted correctly."
end if

this is so it doesn't test a combination twice
COUNT HACKED BY RAZVEEE

RAZVEE IS A SCRIPT KIDDIE- hacker9
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)