There is a program in Pascal, which is engaged in sorting Shell and inserts. The sorting procedures are wonderful and seem to work adequately (if I'm not mistaken), but only with one-dimensional arrays (in this case, the type is LittleDataArray
). You need to adapt them to work with two-dimensional arrays (in this case, the type of LittleDataArray
).
Here are the algorithms:
... DataItem = char; LittleDataArray = array [1..80] of char; DataArray = array [1..80,1..80] of char; ... procedure Shell(var item: LittleDataArray); var i, j, k: integer; h: DataItem; begin amnt_s:=0; k := t shr 1; while k > 0 do begin for i := 0 to t - k do begin j := i; while (j >= 0) and (item[j] > item[j + k]) do begin h := item[j]; item[j] := item[j + k]; inc(amnt_s); item[j + k] := h; inc(amnt_s); if j > k then Dec(j, k) else j := 0; end; end; k := k shr 1; end;
end;
procedure Inser (var item: LittleDataArray); var i, l, j: integer; x: DataItem; begin amnt_i: = 0; for i: = 2 to t do begin x: = item [i]; inc (amnt_i); j: = i-1; while (x0) do begin item [j + 1]: = item [j]; inc (amnt_i); j: = j-1; end; item [j + 1]: = x; inc (amnt_i); end; end; {end Inser sort}