Using QSORT

GFA BASIC-related articles in here please

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

vodkasoda
Atari maniac
Atari maniac
Posts: 94
Joined: Wed Jul 07, 2010 3:55 pm

Using QSORT

Postby vodkasoda » Mon May 13, 2013 11:47 am

I am about to (try to) use QSORT to sort an Array but would like to ask the experts about it first :)

I have data similar to this, where Column 1 is H or A & Column 2 (plus 3 & 4 if necessary) is the time (in minutes) :

H1 XXX ATTACK
H3 SMITH OF XXX IS BOOKED
H7 XXX ATTACK
A10 YYY ATTACK
A10 YYY SCORE, XXX 0-1 YYY
A14 JONES OF YYY IS BOOKED
ETC, ETC ...

If I sort this on Columns 2-4 I assume it will get it's knickers in a twist and do something like this :

H1 XXX ATTACK
A10 YYY ATTACK
A10 YYY SCORE, XXX 0-1 YYY
A14 JONES OF YYY IS BOOKED
H3 SMITH OF XXX IS BOOKED
H7 XXX ATTACK

Would I be right ?

So, I need to either add leading zeroes to all my minutes, or create an extra dimension to my array so that the minutes are held on their own ... but even then they will probably need leading zeroes, or will the Sort recognise them as numerics ?

What would be considered as the best way to do something like this ?

Any examples would be appreciated, the explanation in the Manual I have is dreadful !!!

vodkasoda
Atari maniac
Atari maniac
Posts: 94
Joined: Wed Jul 07, 2010 3:55 pm

Re: Using QSORT

Postby vodkasoda » Mon May 13, 2013 4:30 pm

Can anybody help ? I can't even get the Compiler to accept the QSORT command :roll: :oops: !!!

Code: Select all

Qsort Newsletter2$() Offset 1


It looks correct from the manual I have but I am getting a Syntax Error :?

User avatar
Omikronman
Atari Super Hero
Atari Super Hero
Posts: 525
Joined: Wed Dec 01, 2004 12:13 am
Location: Germany
Contact:

Re: Using QSORT

Postby Omikronman » Mon May 13, 2013 4:50 pm

I still have a copy of a classic computing magazine named "happy computer" here with an article about sorting in basic. There are two listings showing the bubble sort and the quick sort lines. I may be able to copy the quick sort lines for you if you like. :-)

vodkasoda
Atari maniac
Atari maniac
Posts: 94
Joined: Wed Jul 07, 2010 3:55 pm

Re: Using QSORT

Postby vodkasoda » Mon May 13, 2013 5:07 pm

If it's not too much trouble, that would be brilliant, thank you ... I am a bit baffled here (as usual) !!!

Omikronman wrote:I still have a copy of a classic computing magazine named "happy computer" here with an article about sorting in basic. There are two listings showing the bubble sort and the quick sort lines. I may be able to copy the quick sort lines for you if you like. :-)

User avatar
Omikronman
Atari Super Hero
Atari Super Hero
Posts: 525
Joined: Wed Dec 01, 2004 12:13 am
Location: Germany
Contact:

Re: Using QSORT

Postby Omikronman » Mon May 13, 2013 5:29 pm

Here it is: Back in the 80´s these were the fastest basic lines to sort an array, named "Quicksort":

Image
Last edited by Omikronman on Thu Jul 25, 2013 9:18 pm, edited 2 times in total.

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 11922
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: Using QSORT

Postby wongck » Tue May 14, 2013 1:11 am

QSort is a build-in function in GFA basic.
There is a short example of it in GFA official doc located at the AF Wiki. Use the search to find it in the page.
Does that example work?

Here is another example.

May be when you use the OFFSET option, you need to add the number of items to sort. Try adding -1 to the end.

Code: Select all

Qsort Newsletter2$() Offset 1, -1


Sorry if this does not help at all. I am not really a GFA coder. :oops:
My Stuff: FB/Falcon CT63+CTPCI_ATI_RTL8139 14+512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2227
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: Using QSORT

Postby lp » Tue May 14, 2013 2:45 am

I think I said this before, get a v2 manual. :roll:

vodkasoda
Atari maniac
Atari maniac
Posts: 94
Joined: Wed Jul 07, 2010 3:55 pm

Re: Using QSORT

Postby vodkasoda » Tue May 14, 2013 9:15 am

Omikronman - Thank you, though I'm hoping to not have to write my own Sort, but the way things are going ...

wongck - Thank you too, but no, using that exact code gives me errors, including on the Qsort line itself !!! In fact, even if I write the simplest of programs, as soon as I enter Qsort, I get a Syntax Error, so I can only assume that this version of GFA Basic (v2.02, pretty old !) I am using doesn't recognise it, though I thought the manual I have was the right one, I now know it definitely isn't :(

lp - I use what I can get, this manual came from simonsunnyboy IIRC (a couple of years ago, possibly), and is for version 3.5, but I haven't been able to find & download an older version.

I am seeing the owner of this game over the weekend, I will see if he is willing to upgrade ...

vodkasoda
Atari maniac
Atari maniac
Posts: 94
Joined: Wed Jul 07, 2010 3:55 pm

Re: Using QSORT

Postby vodkasoda » Tue May 14, 2013 11:25 am

OK, I wrote my own Sort in the end, it seems to work so if anybody is in a similar position to me, here's the code ...

Code: Select all

'
' Sort by Minute
'
If NlCount2%>1
  For myLoop=1 TO NlCount2%-1
    For Ix=1 TO NlCount2%-myLoop
      If Mid$(Newsletter2$(Ix),2,3)>Mid$(Newsletter2$(Ix+1),2,3) THEN
        myTemp$=Newsletter2$(Ix)
        Newsletter2$(Ix)=Newsletter2$(Ix+1)
        Newsletter2$(Ix+1)=myTemp$
      Endif
    Next Ix
  Next myLoop
Endif
'

User avatar
Omikronman
Atari Super Hero
Atari Super Hero
Posts: 525
Joined: Wed Dec 01, 2004 12:13 am
Location: Germany
Contact:

Re: Using QSORT

Postby Omikronman » Tue May 14, 2013 3:48 pm

Are you sure you like to use Quicksort? I have also the original Bubblesort lines here which are very short but not that quick:

Code: Select all

10 FOR I=1 TO 5
20 L=0
30 FOR K=1 TO 5
40 L=L-(A$(I)>=A$(K))
50 NEXT K
60 B$(L)=A$(I)
70 NEXT I


Social Media

     

Return to “GFA BASIC”

Who is online

Users browsing this forum: No registered users and 2 guests