Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minha contribuicao Gnome Sort #48 #69

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions algoritmos_GnomeSort_48/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions algoritmos_GnomeSort_48/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions algoritmos_GnomeSort_48/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions algoritmos_GnomeSort_48/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions algoritmos_GnomeSort_48/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions algoritmos_GnomeSort_48/algoritmos_GnomeSort_48.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file not shown.
39 changes: 39 additions & 0 deletions algoritmos_GnomeSort_48/src/Main.java
Original file line number Diff line number Diff line change
@@ -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);

}
}
}