1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
uses crt;
const MX = 10;
Var T : array [1..MX] of integer;
N,i,k,val : integer;
c : char;
Begin
clrscr;
write('Donnez n 1.. ' ,MX,' : '); Readln(n);
if (n <=0) or (n > MX) then
begin
writeln('n hors limites');
readln;
halt
end;
For i :=1 to n do begin write('T[',i,'] = '); readln(T[i]); end;
writeln;
writeln('Voici la liste');
For i:=1 to n do write(T[i],' ');
writeln;
write('Modifier <M> ou inserer <I> un element:');
repeat
c:=UpCase(ReadKey);
until c in ['I','M'];
writeln(' ',c);
if (c='I') and (n=MX) then
begin
write('Impossible : Liste pleine!');
readln;
halt
end;
if c='M' then
write('Index
modifier <1..',n,'> et nouvelle valeur : ')
else
write('On insere entre k et k+1. donner k 1..',n,'> : ');
read(k);
readln(val);
if ( k < 1) or (k > n ) then
begin
write('k hors limites');
readln;
halt
end;
if c='M' then
begin
For i:=k to n-1 do T[i+1]:=T[i];
T[k]:= val;
end
else
begin
if k < n then
for i:=n downto k+1 do t[i+1]:=t[i];
t[k+1]:=val;
inc(n);
end;
writeln('Nouvelle liste');
For i:=1 to n do Write(T[i],' ');
writeln;
Readln;
End. |
Partager