Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.23 KB | None | 0 0
  1. program SheikerSORT;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. {$R *.res}
  6.  
  7. uses
  8.   System.SysUtils;
  9.  
  10. var
  11.    UserArr: array of Integer;
  12.    N, i, StartIndex, EndIndex: integer;
  13. begin
  14.    Writeln('Enter size of the your array');
  15.    Readln(N);
  16.    Setlength(UserArr, N);
  17.    EndIndex := N - 1;
  18.    for StartIndex := 0 to EndIndex do
  19.       Read(UserArr[StartIndex]);
  20.    StartIndex := 0;
  21.    dec(EndIndex);
  22.    while StartIndex <= EndIndex do
  23.    begin
  24.       for i := StartIndex to EndIndex do
  25.       begin
  26.          if UserArr[i] > UserArr[i+1] then
  27.          begin
  28.             UserArr[i] :=  UserArr[i] xor  UserArr[i + 1];
  29.             UserArr[i + 1] :=  UserArr[i] xor  UserArr[i + 1];
  30.             UserArr[i] :=  UserArr[i] xor  UserArr[i + 1];
  31.          end;
  32.       end;
  33.       inc(StartIndex);
  34.       for i := EndIndex downto StartIndex do
  35.       begin
  36.          if UserArr[i] < UserArr[i - 1] then
  37.          begin
  38.             UserArr[i] :=  UserArr[i] xor  UserArr[i - 1];
  39.             UserArr[i - 1] :=  UserArr[i] xor  UserArr[i - 1];
  40.             UserArr[i] :=  UserArr[i] xor  UserArr[i - 1];
  41.          end;
  42.       end;
  43.       dec(EndIndex);
  44.    end;
  45.    for StartIndex := 0 to N - 1 do
  46.       Write(UserArr[StartIndex], ' ');
  47.    Readln;
  48.    Readln;
  49. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement