Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
quicksort set
#4
Hey aga...I just looked at your code because...well...just because. I don't want to bash or start another style debate, but I want to offer sincere suggestions that would make your code much more readable. Note that these are not really commands, but rather suggestions/my opinion, even though I've worded them as commands.

1) put your code in order. What I mean is, don't perform a function that's not really needed for another 100 lines. Examples include...CLS as first line of code...why is this here? Is this really the first thing the program does? It looks to me like it creates the arrays firs? Why not call RANDOMIZE TIMER just before the first call to RND? If you do this, then each line is much easier to understand, since it appears in the proper context of the program.

2) Learn to block indent with spaces between blocks.

3) use a *few* comments.

4) This is really important...stop using period as a seperator in variable/function names. It makes it look like you are using nested types (are those possible in QB??)

I believe the advantages of doing this are 3-fold. 1) your code would be easy to read/understand, and therefore others might be willing to criticize the code itself, rather than always being blinded with it's incomprehensibility2)you would get more constructive criticism whereby you could learn/interact more with those who might otherwise be willing to understand your work3)you might become a better programmer who can handle larger, more complex projects as you become more organized.

As an example, I post some code you wrote and then a suggested modification:

Your code:
Code:
DECLARE SUB qsort.linked.string.lowstart (array1() AS STRING, array2() AS INTEGER, a.max%)
CLS
RANDOMIZE TIMER
a.max% = 100
DIM array1(1 TO a.max%) AS STRING
DIM array2(1 TO a.max%) AS INTEGER
FOR i% = 1 TO a.max%
temp% = INT(RND * 10) + 1
array1$(i%) = SPACE$(temp%)
FOR j% = 1 TO temp%
IF INT(RND * 2) THEN
MID$(array1$(i%), j%, 1) = CHR$(INT(RND * 26) + 97)
ELSE
MID$(array1$(i%), j%, 1) = CHR$(INT(RND * 26) + 65)
END IF
NEXT j%
array2(i%) = i%
NEXT i%
t1# = TIMER
qsort.linked.string.lowstart array1(), array2(), a.max%
t2# = TIMER
PRINT t2# - t1#
SLEEP
FOR i% = 1 TO a.max%
PRINT array1(i%)
NEXT i%

Edit::: As an example of why to block indent...the last line of code is Next i%...The first thing I did was look what this variable was...and I see the first meat of your code is a FOR i% loop, and I said-A-Ha!!!...but alas, I was wrong Sad

1-way to make it more readable:
Code:
DECLARE SUB QsortLinkedStringLowstart (array1() AS STRING, array2() AS INTEGER, arraySize)

arraySize = 100
DIM array1(1 TO arraySize) AS STRING
DIM array2(1 TO arraySize) AS INTEGER

'Fill arrays with rand data to be sorted
RANDOMIZE TIMER
FOR i% = 1 TO arraySize    
  temp% = INT(RND * 10) + 1
  array1$(i%) = SPACE$(temp%)
  
  FOR j% = 1 TO temp%
    IF INT(RND * 2) THEN
      MID$(array1$(i%), j%, 1) = CHR$(INT(RND * 26) + 97)  'LowerCase Letter
    ELSE
      MID$(array1$(i%), j%, 1) = CHR$(INT(RND * 26) + 65)  'UpperCase letter
    END IF
  NEXT j%
  
  array2(i%) = i%
NEXT i%

'sort it!!
t1# = TIMER
QsortLinkedStringLowstart array1(), array2(), arraySize
t2# = TIMER

CLS: PRINT "The array of "; ArraySize ; " elements was sorted in ";t2# - t1#;" seconds"
SLEEP

FOR i% = 1 TO arraySize
  PRINT array1(i%)
NEXT i%
END

Cheers...HTH
Reply


Messages In This Thread
quicksort set - by Agamemnus - 11-22-2003, 11:46 PM
quicksort set - by relsoft - 11-23-2003, 01:03 PM
quicksort set - by Agamemnus - 11-23-2003, 08:27 PM
quicksort set - by Mango - 12-19-2003, 09:36 PM
quicksort set - by Agamemnus - 12-19-2003, 10:48 PM
quicksort set - by Mango - 12-19-2003, 11:07 PM
quicksort set - by Agamemnus - 12-20-2003, 08:52 AM
quicksort set - by adosorken - 12-20-2003, 09:04 AM
quicksort set - by Agamemnus - 12-20-2003, 09:23 AM
quicksort set - by adosorken - 12-20-2003, 09:32 AM
quicksort set - by Mango - 12-20-2003, 09:46 AM
quicksort set - by adosorken - 12-20-2003, 06:07 PM
quicksort set - by Agamemnus - 12-20-2003, 08:56 PM
quicksort set - by Agamemnus - 06-03-2005, 07:37 PM
quicksort set - by Torahteen - 06-03-2005, 08:01 PM
quicksort set - by Agamemnus - 06-03-2005, 10:15 PM
quicksort set - by Torahteen - 06-03-2005, 10:44 PM
quicksort set - by Agamemnus - 06-03-2005, 10:51 PM
quicksort set - by Moneo - 06-03-2005, 11:17 PM
quicksort set - by Torahteen - 06-04-2005, 01:04 AM
quicksort set - by Agamemnus - 06-04-2005, 01:14 AM
quicksort set - by TheBigBasicQ - 06-07-2005, 01:35 AM
quicksort set - by Agamemnus - 06-10-2005, 06:50 PM
quicksort set - by Agamemnus - 06-10-2005, 09:43 PM
quicksort set - by Ralph - 06-14-2005, 08:21 PM
quicksort set - by MystikShadows - 06-14-2005, 11:23 PM
quicksort set - by SBM Productions - 07-13-2005, 10:22 PM
quicksort set - by Ralph - 07-14-2005, 03:48 AM
quicksort set - by Moneo - 07-15-2005, 11:50 PM
quicksort set - by rpgfan3233 - 07-16-2005, 01:31 AM
quicksort set - by yetifoot - 12-07-2005, 08:40 AM
quicksort set - by Agamemnus - 12-07-2005, 10:01 AM
quicksort set - by Ralph - 12-07-2005, 08:29 PM
quicksort set - by Mango - 12-08-2005, 06:21 AM
quicksort set - by Agamemnus - 12-09-2005, 04:53 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)