Advertisement
Guest User

Selection Sort

a guest
Nov 24th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.72 KB | None | 0 0
  1. Program Pzim ;
  2. Const
  3.    total = 10;
  4. Type
  5.    vetor = array [1..total] of integer;
  6. Var
  7.    k,i,j,aux: integer;
  8.    vet: vetor;
  9. Begin
  10.    write('Vetor: ');
  11.    for k:=1 to total do      //criando vetor randômico
  12.    Begin
  13.       vet[k]:= random(9)+1;
  14.       write(vet[k]);
  15.    End;
  16.      
  17.    for i:=1 to total do       //SelectionSort//
  18.       for j:=i+1 to total do
  19.       Begin
  20.          if (vet[i] > vet[j]) then
  21.          Begin
  22.              aux:= vet[i];
  23.              vet[i]:= vet[j];
  24.              vet[j]:= aux;
  25.          End;
  26.       End;
  27.      
  28.      
  29.    writeln;                   //Mostra Vetor ordenado
  30.    writeln;
  31.    write('Vetor ordenado: ');  
  32.    for k:=1 to total do
  33.       write(vet[k]);
  34.    readln;
  35. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement