diff --git a/algoritmos_GnomeSort_48/.idea/.gitignore b/algoritmos_GnomeSort_48/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/algoritmos_GnomeSort_48/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/algoritmos_GnomeSort_48/.idea/.name b/algoritmos_GnomeSort_48/.idea/.name new file mode 100644 index 0000000..002da1d --- /dev/null +++ b/algoritmos_GnomeSort_48/.idea/.name @@ -0,0 +1 @@ +Main.java \ No newline at end of file diff --git a/algoritmos_GnomeSort_48/.idea/misc.xml b/algoritmos_GnomeSort_48/.idea/misc.xml new file mode 100644 index 0000000..e0844bc --- /dev/null +++ b/algoritmos_GnomeSort_48/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/algoritmos_GnomeSort_48/.idea/modules.xml b/algoritmos_GnomeSort_48/.idea/modules.xml new file mode 100644 index 0000000..ed3c4cd --- /dev/null +++ b/algoritmos_GnomeSort_48/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/algoritmos_GnomeSort_48/.idea/vcs.xml b/algoritmos_GnomeSort_48/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/algoritmos_GnomeSort_48/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/algoritmos_GnomeSort_48/algoritmos_GnomeSort_48.iml b/algoritmos_GnomeSort_48/algoritmos_GnomeSort_48.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/algoritmos_GnomeSort_48/algoritmos_GnomeSort_48.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/algoritmos_GnomeSort_48/out/production/algoritmos_GnomeSort_48/Main.class b/algoritmos_GnomeSort_48/out/production/algoritmos_GnomeSort_48/Main.class new file mode 100644 index 0000000..9605f33 Binary files /dev/null and b/algoritmos_GnomeSort_48/out/production/algoritmos_GnomeSort_48/Main.class differ diff --git a/algoritmos_GnomeSort_48/src/Main.java b/algoritmos_GnomeSort_48/src/Main.java new file mode 100644 index 0000000..840c17f --- /dev/null +++ b/algoritmos_GnomeSort_48/src/Main.java @@ -0,0 +1,39 @@ +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int[] numeros = new int[5]; + System.out.println("Ordenação de vetor Gnome Sort"); + + for (int i = 0; i < 5; i++) { + System.out.println("Digite o " + (i+1) + "º numero aleatório: "); + numeros[i] = scan.nextInt(); + } + System.out.println("Numeros digitados:"); + for (int i = 0; i < 5; i++) { + System.out.print(numeros[i] + ", "); + } + int index = 0; + //int n = numeros.length; + + while (index < numeros.length){ + if (index == 0){ + index++; + } + if (numeros[index] >= numeros[index - 1]){ + index++; + }else { + int temporario = numeros[index]; + numeros[index] = numeros[index - 1]; + numeros[index - 1] = temporario; + index--; + } + } + System.out.println("\nNumeros ordenados:"); + for (int num: numeros) { + System.out.println("\n" + num); + + } + } +} \ No newline at end of file