Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

No wonder Clairol makes so much money selling shampoo. Lather, Rinse, Repeat is an infinite loop!


devel / comp.lang.c / quicksort traume

SubjectAuthor
* quicksort traumefir
`- Re: quicksort traumefir

1
quicksort traume

<utudn7$33vr6$1@i2pn2.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34789&group=comp.lang.c#34789

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!.POSTED!not-for-mail
From: fir...@grunge.pl (fir)
Newsgroups: comp.lang.c
Subject: quicksort traume
Date: Tue, 26 Mar 2024 13:06:06 +0100
Organization: i2pn2 (i2pn.org)
Message-ID: <utudn7$33vr6$1@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 26 Mar 2024 12:05:59 -0000 (UTC)
Injection-Info: i2pn2.org;
logging-data="3276646"; mail-complaints-to="usenet@i2pn2.org";
posting-account="+ydHcGjgSeBt3Wz3WTfKefUptpAWaXduqfw5xdfsuS0";
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
X-Spam-Checker-Version: SpamAssassin 4.0.0
 by: fir - Tue, 26 Mar 2024 12:06 UTC

quicksort trauma

i remmeber back then i was revriting quicksort form
wikipedia or some other poage and tested multiple
versions of it
at some moment i changed something (as i remember i
repleced do while on while this way it seemd to me
it should work but i made some mistake and some
versions were wrong and i not noticed that
- later i afair repaired that but in my
older codes i got verions which im not sure is for
sure right or not

for example this one

void QuicksortInts7(int* table, int lo, int hi)
{

int i=lo; int j=hi;

while (i<hi)
{
int pivot =table[(lo+hi)/2];
while (i<=j) // Partition
{
while (table[i]<pivot) i++;
while (table[j]>pivot) j--;
if (i<=j)
{
int t=table[i];table[i]=table[j];table[j]=t;
i++; j--;
}
}

if (lo < j){ QuicksortInts7(table, lo, j);} //recursion
lo=i; j=hi;
}
}

how can i be sure this is right?? do generation of random array
and comoper results with say qsort from c-lib is enough?

Re: quicksort traume

<uu0r4k$371lj$1@i2pn2.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34793&group=comp.lang.c#34793

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!.POSTED!not-for-mail
From: fir...@grunge.pl (fir)
Newsgroups: comp.lang.c
Subject: Re: quicksort traume
Date: Wed, 27 Mar 2024 11:07:14 +0100
Organization: i2pn2 (i2pn.org)
Message-ID: <uu0r4k$371lj$1@i2pn2.org>
References: <utudn7$33vr6$1@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 27 Mar 2024 10:07:16 -0000 (UTC)
Injection-Info: i2pn2.org;
logging-data="3376819"; mail-complaints-to="usenet@i2pn2.org";
posting-account="+ydHcGjgSeBt3Wz3WTfKefUptpAWaXduqfw5xdfsuS0";
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
In-Reply-To: <utudn7$33vr6$1@i2pn2.org>
X-Spam-Checker-Version: SpamAssassin 4.0.0
 by: fir - Wed, 27 Mar 2024 10:07 UTC

fir wrote:
> quicksort trauma
>
>
> i remmeber back then i was revriting quicksort form
> wikipedia or some other poage and tested multiple
> versions of it
> at some moment i changed something (as i remember i
> repleced do while on while this way it seemd to me
> it should work but i made some mistake and some
> versions were wrong and i not noticed that
> - later i afair repaired that but in my
> older codes i got verions which im not sure is for
> sure right or not
>
> for example this one
>
>
>
> void QuicksortInts7(int* table, int lo, int hi)
> {
>
> int i=lo; int j=hi;
>
> while (i<hi)
> {
> int pivot =table[(lo+hi)/2];
> while (i<=j) // Partition
> {
> while (table[i]<pivot) i++;
> while (table[j]>pivot) j--;
> if (i<=j)
> {
> int t=table[i];table[i]=table[j];table[j]=t;
> i++; j--;
> }
> }
>
> if (lo < j){ QuicksortInts7(table, lo, j);} //recursion
> lo=i; j=hi;
> }
> }
>
>
> how can i be sure this is right?? do generation of random array
> and comoper results with say qsort from c-lib is enough?

this version above seem to work but i only compare to correctnes by
compare to qsort results and if tryin to revrite quicksort it opens
small hell to me so hard is to debiug this, and why something is errorous

this above i sucpect (though not know, maybe not) probably could be
simplified but revriting is hard

mainy i dislike those conditions like in while headers imo conditions
in the middle that calls break should be better, but tryin to revrite id
i spend 3-4 hours and failed

though its rare exampel of code i do not fully understand in a form of
usueal micrologic - and i at least closed to understand it so next time
i can revrite it probably and fully understand it

quicksort btw is somewhat strughtforward reccurency metgod - as it goes
divide on tqwo parts and call itself on the parts (where divide on two
parts i swipe lower on the left and upper on the right so in fact
its quite simple

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor