TrabalhosGratuitos.com - Trabalhos, Monografias, Artigos, Exames, Resumos de livros, Dissertações
Pesquisar

Exercicios de ordenação

Por:   •  26/3/2016  •  Artigo  •  745 Palavras (3 Páginas)  •  148 Visualizações

Página 1 de 3

1) Preencha a tabela com a instancia do vetor ao fim de cada iteração do laço externo.

a)

public void InsertionSort(int[] vet)

{

  for (c = 1 ; c <= 14; c++) {

    d = c;

    while ( d > 0 && vet [d] < vet [d-1]) {

              t= vet [d];

              vet[d]   = vet [d-1];

              vet [d-1] = t;

 

              d--;

    }

}

Pos

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

Vlr

44

22

39

12

14

18

16

07

29

90

22

60

48

57

03

b)

public void Bubblesort(int[] vet)

{

  int aux;

  for (int i = 14 ; i >= 0; i--)

  {

    for (int j = 1; j <= i; j++)

    {

      if (vet[j - 1] > vet[j])

      {

         aux = vet[j];

         vet[j] = vet[j - 1];

         vet[j - 1] = aux;

      }

    }

  }

}

Pos

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

Vlr

44

22

39

12

14

18

16

07

29

90

22

60

48

57

03

c)

public void SelectionSort(int[] vet) {   

  for ( i = 0 ; i <  14 ; c++ )

   {

      position = i;

      for ( j = i + 1 ; j < 15 ; d++ )

      {

         if ( vet[position] > vet[j] )

            position = j;

      }

      if ( position != i )

      {

         aux = vet[i];

         vet[i] = vet[position];

         vet[position] = aux;

...

Baixar como (para membros premium)  txt (8.4 Kb)   pdf (112.9 Kb)   docx (16.2 Kb)  
Continuar por mais 2 páginas »
Disponível apenas no TrabalhosGratuitos.com