0
I have to implement the ordering method Insertion Sort in Pascal.
The problem is that in my algorithm I’m having to do several if
s. One for each possibility.
I wonder if there is a better method to do this.
My code:
Program insertion_sort ;
var
cont , aux : integer ;
numero : array[1..5] of integer ;
Begin
for cont := 1 to 5 do
begin
writeln('Digite um numero : ');
read(numero[cont]);
end;
for cont := 1 to 5 do
begin
if(numero[1] > numero[2]) then
begin
aux := numero[1] ;
numero[1] := numero[2] ;
numero[2] := aux;
end;
writeln(numero[cont]);
end;
End.
Young man, do not use external sources to post your code. If you paste it in the question, select the code text and click
Ctrl
+K
it will get formatted.– Jéf Bueno
I didn’t know I couldn’t , but vlw
– Matheus Macedo