Algorithm for vector ordering

Asked

Viewed 51 times

0

Good morning. My question is on line 9. The correct one would be:

para j de i + 1 até 3 passo 1 faça

or

para j de i + 1 até 3 faça

Follow the complete algorithm:

Algoritmo numero_crescente
      var vet: vetor[1..3] de inteiro
          i,j,aux:inteiro
Inicio
      para i de 1 até 3 passo 1 faça
            Escreva("Digite um numero")
            Leia(vet[i])
      Fim-para
      para i de 1 até 2 passo 1 faça
          para j de i + 1 até 3 passo 1 faça
              se vet[i] > vet[j] entao
                aux <- vet[j]
                vet[j] <- vet[i]
                vet[i] <- aux
               Fim-se
          Fim-para
      Fim-para
      para i de 1 até 3 passo 1 faça
          Escreva(vet[i])
      Fim-para   
Fim
  • another doubt in this sequence I’m making J worth 2 and in the loop it worth 3 ? for i from 1 to 2 step 1 do for j from i + 1 to 3 step 1 do

1 answer

0


Whatever. When you do not put the value of the step, it is understood that such value is 1.

The algorithm you implement is a variant of Selection Sort. However, so you can better glimpse your behavior, I suggest you use a vector with more than 3 elements only.

  • vlw, can you let me know if there are any errors in this algorithm ?

  • @Rafaellopes Reply edited.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.