A small snippet of code may be helpful to sort more than one array simultaneously, i.e pairs of related x,y data. The time needed for sorting two arrays x and y is about 1.4 seconds on my device. The code can easily be extended for more than two arrays.
REM Multiple array sort
randomize 0 anz=10 DIM x[anz], y[anz] ! Generate some data FOR i=1 TO anz x[i]=10*RND() : y[i]=1/x[i] print x[i],y[i] NEXT i
! Sort t1=TIME() FOR i=1 TO anz-1 ARRAY.MIN mn,x[i,anz-i+1] ARRAY.SEARCH x[i,anz],mn,pos SWAP x[i],x[pos+i-1] SWAP y[i],y[pos+i-1] NEXT i t2=TIME()
Joined: Wed Oct 03, 2012 9:53 am Posts: 2795 Location: Colorado, U.S.
If you just put a variable name on a line by itself, BASIC! creates that variable and initializes it to 0 or "", depending on type.
Also, when BASIC! is executing it ignores all spaces (outside of quotes). "go to x y z" is the same as "goto xyz". Or "gotoxyz".
Last piece of the puzzle: RANDOMIZE is a function, so you have to say something like "x = RANDOMIZE(0)". (Always returns 0, which makes no sense, but that's another story.)
So the statement RANDOMIZE 0 creates a variable named "RANDOMIZE0" and initializes it to 0.
This "bare variable is a complete statement" rule is quite recent. If your experience with "RANDOMIZE 0" makes you think it's a bad idea, you are not alone. Read this topic. Although I did not say so there, I did change the behavior. In v01.90, your "RANDOMIZE 0" will generate a syntax error.
Users browsing this forum: No registered users and 1 guest
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum