forked from heitor582/Algoritmos-e-Estruturas-de-Dados
-
Notifications
You must be signed in to change notification settings - Fork 0
/
selectsort.pas
96 lines (84 loc) · 1.29 KB
/
selectsort.pas
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
program selection_sort;
uses crt;
const
MAX = 10;
type
Tdado = integer;
Tvetor = array[1..MAX] of Tdado;
var
vetor : Tvetor;
//usado para tester
procedure preencher(var vetor : Tvetor);
begin
vetor[1] := 4;
vetor[2] := 3;
vetor[3] := 500;
vetor[4] := 7;
vetor[5] := 10;
vetor[6] := 1309;
vetor[7] := 8;
vetor[8] := 9;
vetor[9] := 2;
vetor[10] := 6;
end;
procedure manual(var vetor:Tvetor);
var
i : integer;
begin
for i := 1 to MAX do
begin
writeln('informe o valor ',i);
readln(vetor[i]);
end;
end;
// acha o menor, nucleo do programa
procedure kernel(var vetor : Tvetor; pos : integer);
var
aux : integer=0;
j: integer;
menor : integer;
begin
menor := pos;
for j:= pos+1 to MAX do
begin
if vetor[menor] > vetor[j] then
begin
menor := j;
end;
end;
aux := vetor[pos];
vetor[pos] := vetor[menor];
vetor[menor] := aux;
end;
//////////////////////////////
procedure exibir(vetor: Tvetor);
var
i : integer;
begin
writeln;
write(' | ');
for i:=1 to MAX do
begin
write(vetor[i]);
write(' | ');
end;
writeln;
end;
procedure repetir();
var
i: integer;
begin
for i:=1 to MAX-1 do
begin
kernel(vetor,i);
end;
end;
begin
manual(vetor);
writeln('Vetor Original');
exibir(vetor);
repetir();
writeln;
writeln('Vetor Ordenado');
exibir(vetor);
end.