🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #15255

Re: Threads and quicksort

#15255
From: Steve Schafer (TeamB)
Date: Mon, 28 Jun 1999 00:00
27 lines
1559 bytes
On Mon, 28 Jun 1999 00:10:31 +0200, "Vincent Wolowski"
<vwolowski@t-online.de> wrote:

>Can someone tell me how to program quicksort with threads?

Quicksort works by partitioning the array of items to be sorted into
two groups, where all of the items in one group are guaranteed to sort
before all of the items in the other group. It then sets to work on
the two groups, partitioning each of them into two subgroups, and so
on. Since sorting each of a pair of groups is independent of sorting
the other member of the pair, the two groups may be sorted in separate
threads.

So the basic pseudocode (not including various optimizations) might
look something like this:

 function QuickSort(array of items)
 begin
 if array contains only one element, exit
 partition array of items into two subarrays; call them left_array
   and right_array
 start a new thread
 in the context of the new thread, QuickSort(right_array)
 in the context of the current thread, QuickSort(left_array)
 end

-Steve
Technical Details
Message-ID: <3780f733.21114879@90.0.0.40>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7l67ok$6km$1@news01.btx.dtag.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,9e5cdef026dde577
X-Google-Attributes: gidf74b3,public
From: pandeng@telepath.com (Steve Schafer (TeamB))
Subject: Re: Threads and quicksort
Date: 1999/06/28
Message-ID: <3780f733.21114879@90.0.0.40>
X-Deja-AN: 494643985
Content-Transfer-Encoding: 7bit
References: <7l67ok$6km$1@news01.btx.dtag.de>
Content-Type: text/plain; charset=us-ascii
Organization: TeamB
Mime-Version: 1.0
Reply-To: pandeng@telepath.com
Newsgroups: borland.public.jbuilder.java.language