Advertisement
ArXen42

Операции с массивами

Sep 30th, 2015
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.66 KB | None | 0 0
  1. unit ArrayOpers;
  2. {-------------------------------------------------------------------------}
  3. interface
  4.  procedure Swap(var a, b:longint);
  5.  procedure FillArray(var arr : array of longint; arrsize, range: integer);
  6.  procedure WriteArray(var arr : array of longint; arrsize:integer);
  7.  procedure IsSorted(var arr : array of longint; arrsize:integer);
  8.  procedure EquateArrays(var arr1, arr2 : array of longint; arrsize:integer);
  9. {-------------------------------------------------------------------------}
  10. implementation
  11.  
  12.  procedure Swap(var a, b:longint);
  13.  var temp:integer;
  14.  begin
  15.   temp:= a;
  16.   a:=b; b:=temp;
  17.  end;
  18.  
  19.  procedure FillArray(var arr : array of longint; arrsize, range: longint);
  20.  var i:longint;
  21.  begin
  22.   for i:= 0 to  arrsize - 1 do
  23.   arr[i]:= random(range);
  24.  end;
  25.  
  26.  procedure WriteArray(var arr : array of longint; arrsize:integer);
  27.  var i:integer;
  28.  begin
  29.   for i:= 0 to arrsize - 1 do
  30.    write(arr[i],' ');
  31.   writeln();
  32.  end;
  33.  
  34.  procedure IsSorted(var arr : array of longint; arrsize : integer);
  35.  var i:integer;
  36.      flag:boolean;
  37.  begin
  38.   flag:= true;
  39.   i:=1;
  40.   while ((i < arrsize-1) and (flag)) do
  41.   begin
  42.    if (arr[i] <= arr[i+1]) then inc(i) else
  43.    flag:=false;
  44.   end;
  45.   if (flag) then writeln('Sorted of inc') else
  46.   begin
  47.    i:=1;
  48.    flag:= true;
  49.    while ((i < arrsize-1) and (flag)) do
  50.    begin
  51.     if (arr[i] >= arr[i+1]) then inc(i) else
  52.     flag:=false;
  53.    end;
  54.    if (flag) then writeln('Sorted of dec')
  55.    else writeln('Not sorted');
  56.   end;
  57.  end;
  58.  
  59.  procedure EquateArrays(var arr1, arr2: array of longint; arrsize: integer);
  60.  var i:integer;
  61.  begin
  62.   for i:= 0 to arrsize-1 do
  63.   arr2[i]:=arr1[i];
  64.  end;
  65.  
  66. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement