[futurebasic] Re: [FB] Compact QuickSort

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 2001 : Group Archive : Group : All Groups

From: tedd <tedd@...>
Date: Thu, 15 Nov 2001 12:03:17 -0500
>tedd,
>
>I'm a little dense here. What do you mean in comment 2?
>
>I know when the function executes, it grabs the machine. Do you mean 
>adding a timing event to allow an interrupt? Of would a DO : 
>HANDLEEVENTS: UNTIL 0 : END take care of it? Can you take my code 
>and give me a little example?

The above is fine. I only meant to comment that when someone presents 
a program for review, they normally make it a stand-alone program. 
Adding a HANDLEEVENTS or INPUT">":a$ or a UNTIL BUTTON(0) would do 
that.

>You, Jay and Robert P. are so far ahead of me when it comes to 
>sorting that I beg mercy. I'm looking for something simple that I 
>can understand and use. This started out in VB, but after a severe 
>translation using all the FB^3 shorthand I'm aware of, it now bears 
>no resemblance to the original. When I first saw it, I was struck by 
>how compact the code is, but at the same time versatile. (The VB 
>code allowed the array to be dimmed as a variant-- there is no 
>counterpart to variant in FB^3-- which allowed the function to 
>automatically sort whatever kind of variable was thrown at it.)

The code is very similar to my code (tedd's QuickSort) -- you can't 
change the fundamental concept much. Besides, neither of us invented 
the code, we just re-present it.

>I have already used this code with a binary array search function 
>and it seems to work very well. However, my search function only 
>returns the last item of a given element in an array. For instance, 
>if I have a 30-element string array with the 6th and 29th elements 
>being the string "tedd", it will only return the 29th element. I 
>sure would like to find a search function that finds the location of 
>all identical elements.

Now, search is another matter. There are all sorts of search 
algorithms. The code you presented was only a sort.

My solution to most things like that is to use a linked list (tedd's 
Linked List) -- they can be searched very quickly. If you have a much 
larger database to search through, then using a r/b binary tree will 
be much, much , much quicker.

>On my G3 350 I consistently get between 110-120 ticks. I'm assuming 
>you're using a G4. In your experience, how does this rate speedwise?

Oh, your machine is too slow -- if it were mine I'd give it the boot 
( :-) ). Actually, mine is only a G3/500 but it's not too shabby at 
the present time, but next week... well, who knows? Besides, two 
seconds to do a sort should be no problem for any user. It's when 
they have to watch the cursor spin that you really need to do 
something about speed -- IMHO.

tedd
-- 
http://sperling.com