Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sorting
#1
Ok.. Im new here.. Im looking for help on how to sort numbers and letters..

example..

811 Typing

I need to sort a read/data line so that this will sort ascending and descending...
Im still kinda new at this. I have some labs needing done in a few weeks and im still stuck on one of them. Just trying to finish so i dont fail..

Ive read on sorting but maybe im still lost..
Reply
#2
The <, <=, >, and >= operators work with strings that same way they do with numbers.

Like so:
[syntax="qbasic"]IF stringArray$(1) > stringArray$(2) THEN
' Ooops, looks like #1 and #2 are out of order
SWAP stringArray$(1), stringArray$(2) ' trade places
END IF[/syntax]
Reply
#3
will this work the same if using a swap is not allowed.
Reply
#4
You mean not using the SWAP function? Yes, it will still work.
Code:
IF stringArray$(1) > stringArray$(2) THEN
  ' Ooops, looks like #1 and #2 are out of order
  temp$=stringArray$(1)
  stringArray$(1)=stringArray$(2)
  stringArray$(2)=temp$  
END IF
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#5
Sweet. Thanks a million.. Now to get this one done and figure the last 3 out..lol.. Thanks again..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)