English
Source / code snippets

Nonrekursives QUICKSORT for 4-byte-Integer-Arrays

 

p.specht

for the to testing. 500.000 4-byte-Zufallsintegers in XProfan11.2a need my 2.5 GHz computer (Profan rechnet thereby only on one core) of these Algorithmus 186 sec. Nostalgie purely ...
for such Arraygrößen Please The row with Locate 2,2 comment, otherwise can itself during the Zufallsgenerierung a coffee make weg.
greeting
Window Title "NONREKURSIVES QUICKSORT"
'Getestet, but without Gewähr, P. woodpecker in XProfan-11.2a free
Declare NumMax&,A&[],Stack1&[],Stack2&[],StackPtr&,HeadPtr&,TailPtr&
declare Pivot&,a&,b&,t&,q&,r&,p&,s&
declare i&,ms1&,sec!
Jump0:
Cls
Print "Wieviele Random Numbers?:";
Input NumMax&
Randomize:i&=0

While i&<NumMax&

    A&[i&]=Rnd(100000)
    Locate 2,2:print i&,A&[i&]''''
    Inc i&

EndWhile

ms1& = &GetTickCount''''
StackPtr&=0
HeadPtr&=0
TailPtr&=NumMax&-1
Print "Starte Nonrekursives Quicksort...";''''
Jump2:

While HeadPtr& < TailPtr&

    Pivot& = A&[(HeadPtr& + TailPtr&)/2]
    a& = HeadPtr&
    b& = TailPtr&
    Jump1:

    While A&[a&] < Pivot&

        inc a&

    EndWhile

    While A&[b&] > Pivot&

        dec b&

    EndWhile

    If a& < b&

        t&=A&[a&]
        A&[a&]=A&[b&]
        A&[b&]=t&
        inc a&
        dec b&
        Goto "Jump1"

    EndIf

    If a&=b&

        q& = b& - 1
        r& = a& + 1

    Else

        q& = b&
        r& = a&

    EndIf

    inc StackPtr&
    p& = HeadPtr&
    s& = TailPtr&

    If (q&-p&) < (s&-r&)

        Stack1&[StackPtr&] = r&
        Stack2&[StackPtr&] = s&
        HeadPtr& = p&
        TailPtr& = q&

    Else

        Stack1&[StackPtr&] = p&
        Stack2&[StackPtr&] = q&
        HeadPtr& = r&
        TailPtr& = s&

    EndIf

EndWhile

If StackPtr& > 0

    HeadPtr& = Stack1&[StackPtr&]
    TailPtr& = Stack2&[StackPtr&]
    dec StackPtr&
    Goto "Jump2"

EndIf

' Sorting ready
sec!=(&GetTickCount - ms1&)/1000
print:Print "Kontrollausgabe (each " + st$(int(NumMax&/30+1))+". element):"''''

WhileLoop 0,NumMax&-1,int(1+NumMax&/30)

    Print A&[&Loop];
    EndWhile:print''''
    print:print "Dauer the reinen Sortiervorgangs the "+st$(NumMax&)+" Zufallsvariablen: "+st$(sec!)+" Sek."
    print:print "Weiterer Test with beliebiger Button..."
    WaitInput
    Goto "Jump0"
 
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
04/11/21  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

593 Views

Untitledvor 0 min.
Erhard Wirth06/14/24
p.specht07/30/22
N.Art07/23/21
Glubbfan06/19/21
More...

Themeninformationen

this Topic has 1 subscriber:

p.specht (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie