SHARE
TWEET

Untitled

a guest Feb 18th, 2020 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. procedure Merge(var Arr: NArr; Left, Right: Integer);
  2. var
  3.    Middle, Start, Last, i: Integer;
  4.    Mass: array[0..100] of Integer;
  5. begin
  6.    Middle := (Left + Right) div 2;
  7.    Start := Left;
  8.    Last := Middle + 1;
  9.    for i := Left to Right do
  10.       if (Start <= Middle) and ((Last > Right) or (Arr[Start] < Arr[Last])) then
  11.       begin
  12.          Mass[i] := Arr[Start];
  13.          Inc(Start);
  14.       end
  15.       else
  16.       begin
  17.          Mass[i] := Arr[Last];
  18.          Inc(Last);
  19.       end;
  20.    for i := Left to Right do
  21.       Arr[i] := Mass[i];
  22. end;
  23.  
  24.  
  25. procedure MergeSort(var Arr: NArr; Left, Right: Integer);
  26. begin
  27.    if Left < Right then
  28.    begin
  29.       MergeSort(Arr, Left, (Left + Right) div 2);
  30.       MergeSort(Arr, (Left + Right) div 2 + 1, Right);
  31.       Merge(Arr, Left, Right);
  32.    end;
  33. end;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top