const
size = 100 ;
randomInt = 30 ;
type
A = array [ 1 .. size ] of Integer ;
var
TMass: A;
menuInt, menuInt2, N : Integer ; // N - количество элементов
procedure Input( var TMass: A) ; // Запись массива вручную
var i: Integer ;
begin
writeln ( 'Введите N: ' ) ;
read ( N) ;
writeln ( 'Введите массив: ' ) ;
for i: = 1 to N do
readln ( TMass[ i] ) ;
end ;
procedure Output( TMass: A) ; // Вывод
var i: integer ;
begin
for i: = 1 to N do
write ( TMass[ i] , ';' ) ;
end ;
procedure randomGenerate( var TMass: A) ; // Рандомная последовательность
var a, i: integer ;
begin
writeln ( 'Количество элементов: ' ) ;
read ( N) ;
randomize;
for i: = 1 to N do begin
a : = random( N) ;
TMass[ i] : = a;
end ;
writeln ( 'Массив сгенерирован' ) ;
end ;
procedure BubbleSortv1( var TMass: A) ; // Пузырьковая сортировка версия 1
var j, i : integer ;
WasSwap : Boolean ;
begin
for j: = 1 to N do begin
WasSwap : = False ;
for i: = 1 to N- j do begin
if TMass[ i] > TMass[ i+ 1 ] then begin
Swap( TMass[ i] , TMass[ i+ 1 ] ) ;
WasSwap : = True ;
end ;
end ;
If WasSwap = False then exit;
end ;
end ;
procedure BubbleSortv2( var TMass: A) ; // Пузырьковая сортировка версия 2
var R, j : integer ;
WasSwap : Boolean ;
begin
R: = N;
WasSwap: = True ;
while ( R>1 ) and WasSwap do begin
WasSwap : = False ;
for j: = 1 to R- 1 do
if TMass[ j] > TMass[ j+ 1 ] then begin
Swap( TMass[ j] , TMass[ j+ 1 ] ) ;
WasSwap: = True ;
end ;
Dec( R) ;
end ;
end ;
procedure InsertionSort( var TMass: A) ; // Простые вставки
var i, j, R : integer ;
begin
for i : = 2 to N do begin //
R : = TMass[ i] ;
j : = i - 1 ; // левая граница
while ( R < TMass[ j] ) and ( j > 0 ) do begin
TMass[ j+ 1 ] : = TMass[ j] ;
Dec( j) ;
end ;
TMass[ j+ 1 ] : = R;
end ;
end ;
procedure FastSort( var TMass: A; L, R: Integer ) ; // Быстрая сортировка
var i, j, medium: integer ;
begin
i : = L;
j : = R;
medium : = TMass[ ( L+ R) div 2 ] ;
repeat
while TMass[ i] < medium do Inc( i) ; // i увел-ем до тех пор, пока i-ый элемент не окажется больше опорного(расширяем левую часть)
while medium < TMass[ j] do Dec( j) ; // j уменьшаем до тех пор, пока j-ый элемент не окажется меньше опорного(сокращаем правую часть)
if i <= j then begin
if TMass[ i] > TMass[ j] then begin
Swap( TMass[ i] , TMass[ j] ) ;
Inc( i) ;
Inc( j) ;
end ;
end ;
until i>j;
if L<j then FastSort( TMass, L, j) ; // Рекурсивно упорядочиваем подмассивы, лежащие слева и справа от опорного элемента
if i<R then FastSort( TMass, i, R) ;
end ;
procedure Menu( ) ; // Меню
var L, R : integer ;
begin
writeln ( 'Выберите метод заполнения' #10 '№1.Ручной метод' #10 '№2.Случайно сгенерированный' ) ;
readln ( menuInt) ; // Выполнение меню
case menuInt of
1 : Input( TMass) ;
2 : randomGenerate( TMass) ;
end ;
writeln ( 'Выберите сортировку' #10 '№1.Пузырёк' #10 '№2.Простые вставки' #10 '№3.Быстрая сортировка' #10 ) ;
readln ( menuInt2) ;
case menuInt2 of
1 : BubbleSortv1( TMass) ; // Пузырек
2 : InsertionSort( TMass) ; // Вставки
3 : FastSort( TMass, L, R) ; // Быстрая сортировка
end ;
end ;
begin // Тело программы
Menu( ) ;
Output( TMass) ;
end .
Y29uc3QKCXNpemUgPSAxMDA7CiAJcmFuZG9tSW50ID0gMzA7Cgp0eXBlCglBID0gYXJyYXkgWzEuLnNpemVdIG9mIEludGVnZXI7Cgp2YXIKCVRNYXNzOiBBOwoJbWVudUludCwgbWVudUludDIsIE4JOiBJbnRlZ2VyOyAvLyBOIC0g0LrQvtC70LjRh9C10YHRgtCy0L4g0Y3Qu9C10LzQtdC90YLQvtCyCgpwcm9jZWR1cmUgSW5wdXQodmFyIFRNYXNzOiBBKTsgLy8g0JfQsNC/0LjRgdGMINC80LDRgdGB0LjQstCwINCy0YDRg9GH0L3Rg9GOC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C8vINCS0YHRgtCw0LLQutC4CgkJMyA6IEZhc3RTb3J0KFRNYXNzLCBMLCBSKTsgLy8g0JHRi9GB0YLRgNCw0Y8g0YHQvtGA0YLQuNGA0L7QstC60LAKCWVuZDsKZW5kOwoKYmVnaW4gLy8g0KLQtdC70L4g0L/RgNC+0LPRgNCw0LzQvNGLCglNZW51KCk7CglPdXRwdXQoVE1hc3MpOwplbmQuCgo=
compilation info
Free Pascal Compiler version 2.6.4+dfsg-4 [2014/10/14] for i386
Copyright (c) 1993-2014 by Florian Klaempfl and others
Target OS: Linux for i386
Compiling prog.pas
prog.pas(50,5) Error: Wrong number of parameters specified for call to "swap"
prog.pas(68,5) Error: Wrong number of parameters specified for call to "swap"
prog.pas(100,6) Error: Wrong number of parameters specified for call to "swap"
prog.pas(124,27) Warning: Local variable "R" does not seem to be initialized
prog.pas(124,24) Warning: Local variable "L" does not seem to be initialized
prog.pas(133) Fatal: There were 3 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled)
stdout