Created
June 16, 2020 17:30
-
-
Save HenriqueMitsuo/b24ba173912a0a4101ad5bd13441a2ab to your computer and use it in GitHub Desktop.
Atividade Extra - Algoritmo Shell Sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Shellsort; | |
import java.util.Arrays; | |
public class Shell { | |
public void Sort(int vetor[], int tamanho_vetor){ | |
int lacuna; | |
int temporario; | |
for(lacuna = tamanho_vetor / 2; lacuna > 0; lacuna /= 2){ | |
for(int i = lacuna; i < tamanho_vetor; i++){ | |
temporario = vetor[i]; | |
int j; | |
for(j = i; j >= lacuna && vetor[j - lacuna] > temporario; j -= lacuna){ | |
vetor[j] = vetor[j - lacuna]; | |
} | |
vetor[j] = temporario; | |
} | |
} | |
} | |
public static void main(String args []){ | |
Shell shell = new Shell(); | |
int[] vetor = {78, 52, 36, 17, 15, 10, 22, 41, 67}; | |
//int[] vetor = {50,30,40,80,10,20,70,60}; | |
int tamanho = vetor.length; | |
System.out.println("SHELL SORT:"); | |
System.out.println("Tamanho do Array: " + tamanho); | |
System.out.println("Vetor Original: " + Arrays.toString(vetor)); | |
shell.Sort(vetor, tamanho); | |
System.out.println("\nVetor Ordenado: " + Arrays.toString(vetor)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment