Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Seven Bubble sort for you: which do you choose?
#13
Russian Sorting Halves Danilin
2014 ... 2018 ... 2023
https://qb64forum.alephc.xyz/index.php?topic=702

I propose to introduce themes inside main program

Now program zapoln.bas synthesizes file ISX.txt
in program catalog

zapoln.bas

Code: (Select All)
n = 10^5: DIM d(n) ' zapoln.bas

a=1000
b=5000
c=3000
d=7000

RANDOMIZE TIMER

FOR i=1 TO INT(n/4)
    d(i)=INT(RND*100*a)+a
    d(n/4+i)=INT(RND*100*b)+b
    d(n/2+i)=INT(RND*100*c)+c
    d(3*n/4+i)=INT(RND*100*d)+d
NEXT

OPEN "ISX.txt" FOR OUTPUT AS #1

FOR i=1 TO n
PRINT #1, d(i): NEXT

END


Next, program rusort14.bas is sorting
first reads and then sorts 32767 integers
counting time and then writes to file rusort14.txt

rusort14.bas

Code: (Select All)
' DA 2 SIDE MASSIV sort rusort22.bas
n=32767

Dim d(2,n),q(3)

Open "ISX.txt" For Input As #1
For i=1 To n: Input #1,d(1,i): Next

For k=n-10 To n: Print d(1,k);: Next: Print
start=Timer: p=0: s=0

Print "SORTING": Print: Print

For i=1 To n: sum1=sum1+d(1,i): Next
sred1=sum1/n: Print sred1: Print

y=1: z=0: For i=1 To n
    If d(1,i) < sred1 Then d(2,y)=d(1,i): y=y+1: Else d(2,n-z)=d(1,i): z=z+1
    '    FOR k=1 TO n: PRINT d(2,k);: NEXT: PRINT
Next: Print

For i=1 To n: sum2=sum2+d(2,i): Next
sred2=sum2/n: Print sred2,y: Print

q(1)=1: q(2)=y-1: q(3)=n

For t=1 To 2
    For i=q(t) To q(t+1): For j=i+1 To q(t+1)
        If d(2,i) > d(2,j) Then Swap d(2,i),d(2,j): p=p+1
        s=s+1: Next: '    FOR k=1 TO n: PRINT d(2,k);: NEXT: PRINT
    Next
Next

finish=Timer

For i=1 To n: sum3=sum3+d(2,i): Next: sred3=sum3/n: Print

For i=n-10 To n: Print d(2,i);: Next: Print
Print finish-start,s,p

Open "rusort14.txt" For Output As #2
For i=1 To n: Print #2,d(2,i): Next






Then it is possible to compare time
taking into account: my current version is with key 2
and there are developments for key 4 and key 8

Personally, if I translate into theme style
I think it will take too much time






All know ?

Quick sorting was invented in 1960
when author american was an in USSR
Write name of program in 1st line to copy & paste & save filename.bas
Insert program pictures: press print-screen-shot button
Open paint & Paste & Save as PNG
Add picture file to program topic

Russia looks world from future. Big data is peace data.
I never recommend anything & always write only about myself
Reply


Messages In This Thread
RE: Seven Bubble sort for you: which do you choose? - by DANILIN - 03-13-2023, 05:00 AM



Users browsing this thread: 2 Guest(s)