Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
quicksort set
#21
Thanks Moneo.

I usually hang around neobasic.net.


Torahteen, yes indeed. I agree to disagree with you about it. :lol:
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#22
wow talk about bringing the dead back to life! :lol:

Hey aga, not seen you around for a LONG time Wink
Reply
#23
hi.

omg you've turned to the heathens.. (linux)
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#24
I have made comments to make it customizable. I want to make the comments as user friendly as possible. Please help me.


Code:
'The sub can use amax, amin, and array2() as optional values.
SUB qsort.integer.lowstart (array1() AS INTEGER, amax AS INTEGER)
DIM g2(1 TO 32) AS INTEGER, h2(1 TO 32) AS INTEGER 'Holds the ranges to sort and helps calculate pivot positions. This value should be at least log(UBOUND(array1)).

DIM e as INTEGER 'should be be able to hold at least log(UBOUND(array1)) + 1.
DIM i AS INTEGER, j AS INTEGER, r AS INTEGer, g AS INTEGER, h AS INTEGER 'These values should be able to hold a value of at least UBOUND(array1).
DIM k AS INTEGER 'this should be the same value as the array to sort. (array1())
e = 1
g2(1) = 1 'The starting position of the sort. Set it to LBOUND for the array min value.
h2(1) = amax 'The ending position of the sort. Set it to UBOUND for the array max value.

1
g = g2(e)
h = h2(e)
2 j = g: i = h: r = (g + h) \ 2: k = array1(r)

'to switch from a low to high order or vice versa, just switch these two signs:
'low to high:
'array1(j) < k
'array1(i) > k
'high to low:
'array1(j) > k
'array1(i) < k
3 IF array1(j) < k THEN j = j + 1: GOTO 3
4 IF array1(i) > k THEN i = i - 1: GOTO 4

IF j > i THEN GOTO 7
'To add an array linked to this one, swap it here too. ie: SWAP array2(i), array2(j)
SWAP array1(i), array1(j)
j = j + 1
i = i - 1
IF j > i THEN GOTO 7
GOTO 3

7
IF i + j < h + g THEN
IF j < h THEN g2(e) = j: h2(e) = h: e = e + 1
h = i
ELSE
IF g < i THEN g2(e) = g: h2(e) = i: e = e + 1
g = j
END IF

IF g < h THEN GOTO 2
e = e - 1
IF e THEN goto 1

ERASE g2, h2
END SUB
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#25
Hmm... Why is:

qsort.linked.string.lowstart array1(), array2(), a.max%

easier ot shorter to write than:

qsortLinkedStringLlowstart array1(), array2(), a.max%

Seems to me that "qsort.linked" uses the same keystrokes as "qsortLinked", including ".l" vs. "Shift l".

As to what to use or not to use, I think that's stricktly personal preference and style.

Then, again, there are teachers, who must explain everything. And there are doers, who explain nothing! We really need both kinds, I believe, and we should accept and be at peace with all! After all, nobody can really say what is right and what is wrong, only what appears to one to be right or wrong. It's mainly a matter preference.
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#26
Quote:I personally have zero difficulty looking through Agamemnus' code...as a former "King Of Spaghetti Code", it's easily readable to me Smile

Amen to that Adosorken....back when spaghetti code was "IN" we were "IN" too...ahhh those were the good old days. ;-).
hen they say it can't be done, THAT's when they call me ;-).

[Image: kaffee.gif]
[Image: mystikshadows.png]

need hosting: http://www.jc-hosting.net
All about ASCII: http://www.ascii-world.com
Reply
#27
There was a time spaghetti code was in? I know that Jacques Mallah wrote a tut on unreadable code(3d-jga9 is awesome; how'd he get it so fast?) but it was in once?
am part of the legion of n00b. We are numerous if dumb. We will enslave you all!
Reply
#28
In the beginning, when memory was very, very expensive and everybody used very small-sized memory (I started with 16K!), yes, very-tight code required spegetti-code to get things done, and yes, spgetti-code was the only way to go!

When I look at VBA code, I cry at the tremendous waste and super-excessive verbosity. Shudder.
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#29
Your right, Ralph,

I started on an IBM 1401 back in 1961 which only had 4k of core memory. You could buy an additional 4 or 8k which came in a separate box about half the size of a refrigerator.

In those days, we wrote in assembler, which of course used GOTO's all over the place. But, there were also conditional GOTO's, like BE (Branch if Equal), BL (Branch if Low) which you performed immediately after a Compare instruction.
*****
Reply
#30
This must be how binary trees evolved. . . Tongue
974277320612072617420666C61696C21 (Hexadecimal for those who don't know)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)