6. Implementarea mijlocul vectorului ș i al sub ș irurilor m noul vector( ș ir) y pozi ț ia î n noul vector ny contoarele i, j capetele vectorului ș i ale sub ș irului k, p vectorul ini ț ial( ș irul) x num ă rul de elemente aflate î n vector( ș ir) n Denumire Variabile Variabile
7. if j>p then for j:= I to m do begin ny:=ny+1; y[ny]:=x[j]; end; end; end; BEGIN write('n=');readln(n); for i:=1 to n do begin write('x[',i,']=');readln(x[i]); end; inter(x,1,n); for i:=1 to n do write(x[i]:3); readln; END. program divide_et_impera; type x,y=array[1..100]of integer; var x,y:vector; n, i, j, k, p, t, m: integer; procedure interclasare(var x:vector; k,p:integer); begin If (p-k)>=1 then begin if x[k]>x[p] then begin aux:=x[k]; x[k]:=x[p]; x[p]:=aux; end; end else begin m:=trunc(p+k)div 2; interclasare(x,k, trunc(k+p)/2); interclasare(x, trunc((k+p)/2+1), p); i:=k; t:=m+1; ny:=1; j:=p; While (i<=m)and(j<=p)do if x[i]<x[j] then begin ny:=ny+1; y[ny]:=x[i]; i:=i+1; end else begin ny:=ny+1; y[ny]:=x[j]; j:=j+1; end; if i>m then for i:= j to p do begin ny:=ny+1; y[ny]:=x[i]; end;