From 9cf1fcc123d3927dec7f54947917273bb506be7f Mon Sep 17 00:00:00 2001 From: Erica Luz Date: Tue, 17 Oct 2023 23:44:20 -0300 Subject: [PATCH] minha contribuicao Gnome Sort #48 --- algoritmos_GnomeSort_48/.idea/.gitignore | 3 ++ algoritmos_GnomeSort_48/.idea/.name | 1 + algoritmos_GnomeSort_48/.idea/misc.xml | 6 +++ algoritmos_GnomeSort_48/.idea/modules.xml | 8 ++++ algoritmos_GnomeSort_48/.idea/vcs.xml | 6 +++ .../algoritmos_GnomeSort_48.iml | 11 +++++ .../algoritmos_GnomeSort_48/Main.class | Bin 0 -> 1735 bytes algoritmos_GnomeSort_48/src/Main.java | 39 ++++++++++++++++++ 8 files changed, 74 insertions(+) create mode 100644 algoritmos_GnomeSort_48/.idea/.gitignore create mode 100644 algoritmos_GnomeSort_48/.idea/.name create mode 100644 algoritmos_GnomeSort_48/.idea/misc.xml create mode 100644 algoritmos_GnomeSort_48/.idea/modules.xml create mode 100644 algoritmos_GnomeSort_48/.idea/vcs.xml create mode 100644 algoritmos_GnomeSort_48/algoritmos_GnomeSort_48.iml create mode 100644 algoritmos_GnomeSort_48/out/production/algoritmos_GnomeSort_48/Main.class create mode 100644 algoritmos_GnomeSort_48/src/Main.java 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 0000000000000000000000000000000000000000..9605f3392d0a2f6641eb02f1b95659afd4de1ad9 GIT binary patch literal 1735 zcmaJ>-%nd*7=FI~I_+5zR@On?3TMJ5Y?V$Y%+ZN%os4Q3b4BKyS^Q{E;EeX1=Jb?| z#G56%@y^7=7%xo33$C5XNN^#>d9_{nFKE2+FEC~SpYIf<1Y(nZKc4q}pZEQq_idkU zZEONKkB@Y8VOYcI7|tN0BY;=bX(WoQjgCmNy{~92%Yz2<4rMDbQK8Z1Y;PHgCGKa=uC=QFO|(IwxIA-FLu{w`euUQJj{R zonv&3yTH+*+r_(bS!S!!UdWa_*RmIKid|Uz76f$9tkoTtWDXPC%^E|cyFjY$10rc` zlqGq)TdYmbs%A?>Y|~{@jq#@IFgS3V++oYEnD+!aN}en)P0PAptA+ulEjdlMY))G0 zK`~YHh$=IV!$=4m_DgOj*Dw*sTXhx-L78*YI3fpEkWkr_$(*;A#|8aTM@w9Pgn>RjIM6-Kba#mM1Gt zV?2uKIIbyzZv9`Yz1B1wL;Sp9 zwAyFLswurEKX4?*4S}ATTr%^HU6$TW%Uk5B;Yr(LlaoV*;r-L4#=yMi6>QebN#+~` zMTR_Kzapxj3k^4v^nBXju5gyU>@1l(Gup~GDa&l>iiQu>WIN7Mvn~)XsA;=g6jwsqmT9JhX^MkkDvu7($Q7)@tO{OvY}iFX3}RKAvW_M zDAu-rSDyNRo;|!~(jyxKoK31p_ZKCWt)Gt>o~CxBRa@)jP+1wOL(;$5jNBor?GB1;f2 g(?7t754h{(Ea4_*S;=d>AEEsmvDf|e4S&u31Ew3D!~g&Q literal 0 HcmV?d00001 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