Data Structure

Insertion Sort

Learn data structure by example of insertion sort algorithm

4/20/2021
0 views
insertion-sort-algorithm.cC
begin
    for i := 1 to length[A]-1 do
    begin
        value := A[i];
        j := i - 1;
        done := false;
        repeat
            { To sort in descending order simply reverse
              the operator i.e. A[j] < value }
            if A[j] > value then
            begin
                A[j + 1] := A[j];
                j := j - 1;
                if j < 0 then
                    done := true;
            end
            else
                done := true;
        until done;
        A[j + 1] := value;
    end;
end;
Insertion sortdata structurealgorithminsertion sort algorithm

Loading comments...

Related Examples