Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Algoritma Insertion Sort (Ascending)
- procedure insertionSortAsc(var arr: array of integer; n: integer);
- var i, j, key: integer;
- begin
- for i := 1 to n-1 do
- begin
- key := arr[i];
- j := i - 1;
- while (j >= 0) and (arr[j] > key) do
- begin
- arr[j+1] := arr[j];
- j := j - 1;
- end;
- arr[j+1] := key;
- end;
- end;
- // Algoritma Insertion Sort (Descending)
- procedure insertionSortDesc(var arr: array of integer; n: integer);
- var i, j, key: integer;
- begin
- for i := 1 to n-1 do
- begin
- key := arr[i];
- j := i - 1;
- while (j >= 0) and (arr[j] < key) do
- begin
- arr[j+1] := arr[j];
- j := j - 1;
- end;
- arr[j+1] := key;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement