| |
|
|
p.specht
|
WindowTitle "NONREKURSIVES STRING-QUICKSORT"
Declare NumMax&,A$[],Stack1&[],Stack2&[],StackPtr&,HeadPtr&
Declare TailPtr&,Pivot$,a&,b&,t$,q&,r&,p&,s&,i&,ms1&,sec!,m&: J0:
Cls:Print "Wieviele Random 8-Zeichen-Strings? ";:Input NumMax&
Randomize:i&=0:While i&<NumMax&
A$[i&]=chr$(65+int(@rnd(26)))+chr$(65+int(@rnd(26)))+chr$(65+int(@rnd(26)))+\
chr$(65+int(@rnd(26)))+chr$(65+int(@rnd(26)))+chr$(65+int(@rnd(26)))+\
chr$(65+int(@rnd(26)))+chr$(65+int(@rnd(26)))
'print a$[i&],
Inc i&:EndWhile :ms1&=&GetTickCount:StackPtr&=0:HeadPtr&=0
TailPtr&=NumMax&-1:print :print "Starte Nonrekursives Quicksort...";: J2:
While HeadPtr&<TailPtr& : Pivot$=A$[(HeadPtr&+TailPtr&)/2]
a&=HeadPtr& : b&=TailPtr&: J1:
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 "J1"
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 "J2":EndIf :sec!=(&GetTickCount-ms1&)/1000:print
Print "Kontrollausgabe (jedes " + str$(int(NumMax&/30+1))+". Element):"
WhileLoop 0,NumMax&-1,int(1+NumMax&/30):Print A$[&Loop],:EndWhile :print
print:print "Sort-Dauer per "+str$(NumMax&)+" $-Variablen: "+\
str$(sec!)+" Sek.":print:print "Taste...":WaitInput :Goto "J0"
|
|
|
| Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'... | 14.04.2021 ▲ |
|
|
|