Реализации алгоритмов/Сортировка/Пузырьком: различия между версиями

→‎Nemerle: дополнение
(→‎Nemerle: оформление)
(→‎Nemerle: дополнение)
WriteLine($"Sorted list is a $(arr.ToList())");
</source></big>
== TurboBasic 1.1==
<source lang="qbasic">
CLS
RANDOMIZE TIMER
DEFINT X, Y, N, I, J, D
N = 10 ' 32 766 - 62.7 SEC
DIM Y[N], Y1[N], Y2[N], Y3[N], Y4[N] 'FRE(-1)=21440-21456
 
PRINT " ZAPOLNENIE MASSIVA ELEMENTAMI"
 
FOR X = 1 TO N
Y[X] = X
PRINT Y[X];
NEXT X:PRINT
 
PRINT " PEREMESHIVANIJE ELEMENTOV MASSIVA"
 
PRINT " SLUCHAINYE CHISLA"
 
FOR X = 1 TO N
YD=Y[X]
XS=INT(RND*N)+1
PRINT XS;
Y[X]=Y[XS]
Y[XS]=YD
NEXT X:PRINT
 
PRINT " PEREMESHANNYJ MASSIV"
 
FOR X=1 TO N
PRINT Y[X];
NEXT X:PRINT
 
'ALGORITM "SORTIROVKA PROSTYM OBMENOM" O(N^2)
F=0
MTIMER
FOR J=1 TO N-1 STEP 1
FOR I=1 TO N-J STEP 1
'IF Y[I] > Y[I+1] THEN D=Y[I]:Y[I]=Y[I+1]:Y[I+1]=D:F=1
IF Y[I] > Y[I+1] THEN SWAP Y[I],Y[I+1]:F=1
 
LOCATE 8,1 REM
PRINT " ANYMACIJA SORTIROVKI" REM
LOCATE 9,1 REM
FOR X1=1 TO N REM ANIMATION BLOCK
PRINT Y[X1]; REM
NEXT X1:PRINT REM
DELAY .5 REM
 
NEXT I
IF F=0 THEN EXIT FOR
NEXT J
T1=MTIMER
 
PRINT " OTSORTIROVANNYJ MASSIV"
 
FOR X=1 TO N
PRINT Y[X];
NEXT X:PRINT
PRINT "ELAPSED TIME=";T1
</source>
 
 
[[Категория:Алгоритмы сортировки]]
Анонимный участник