Program MergeSort_Sort_Array; Const Tam=10; Type Tipo_Vetor=Array[1..Tam] of Integer; Procedure Gera_Valores(Var V:Tipo_Vetor); Var cont:Integer; Begin For cont:=1 to Tam Do V[cont]:=random(Tam+1); End; Procedure Exibe_Valores(V:Tipo_Vetor); Var aux:integer; Begin for aux:=1 to Tam do begin write('V[',aux,']=',V[aux]); if aux <> Tam then write(', ') else writeln; end; End; Procedure MergeSort (Var V:Tipo_Vetor); Var Vaux: Tipo_Vetor; Procedure Sort(esq,dir:Integer); Var meio,i1,i2,ia:integer; Begin if esq < dir then begin meio := (esq + dir) div 2; sort(esq,meio); sort(meio+1,dir); i1:=esq; i2:=meio+1; ia:=esq; while (i1 <= meio) and (i2 <= dir) do begin if V[i1] < V[i2] then begin Vaux[ia]:=V[i1]; i1:=i1+1; end else begin Vaux[ia]:=V[i2]; i2:=i2+1; end; inc(ia); end; if i1 > meio then while i2 <= dir do begin Vaux[ia]:=V[i2]; inc(i2); inc(ia); end else while i1 <= meio do begin Vaux[ia]:=V[i1]; inc(i1); inc(ia); end; for ia:=esq to dir do V[ia]:=Vaux[ia]; end; End; Begin sort(1,Tam); End; Var Vetor:Tipo_Vetor; Begin Writeln; Writeln('>> ORDENACAO DE VETORES <<'); Writeln; writeln('Metodo MergeSort'); Gera_Valores(Vetor); Exibe_Valores(Vetor); MergeSort(Vetor); Exibe_Valores(Vetor); readln; End.