Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program SheikerSORT;
- {$APPTYPE CONSOLE}
- {$R *.res}
- uses
- System.SysUtils;
- var
- UserArr: array of Integer;
- N, i, StartIndex, EndIndex: integer;
- begin
- Writeln('Enter size of the your array');
- Readln(N);
- Setlength(UserArr, N);
- EndIndex := N - 1;
- for StartIndex := 0 to EndIndex do
- Read(UserArr[StartIndex]);
- StartIndex := 0;
- dec(EndIndex);
- while StartIndex <= EndIndex do
- begin
- for i := StartIndex to EndIndex do
- begin
- if UserArr[i] > UserArr[i+1] then
- begin
- UserArr[i] := UserArr[i] xor UserArr[i + 1];
- UserArr[i + 1] := UserArr[i] xor UserArr[i + 1];
- UserArr[i] := UserArr[i] xor UserArr[i + 1];
- end;
- end;
- inc(StartIndex);
- for i := EndIndex downto StartIndex do
- begin
- if UserArr[i] < UserArr[i - 1] then
- begin
- UserArr[i] := UserArr[i] xor UserArr[i - 1];
- UserArr[i - 1] := UserArr[i] xor UserArr[i - 1];
- UserArr[i] := UserArr[i] xor UserArr[i - 1];
- end;
- end;
- dec(EndIndex);
- end;
- for StartIndex := 0 to N - 1 do
- Write(UserArr[StartIndex], ' ');
- Readln;
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement