From 7e1fceeb1fe8a488fb3174d0cbc64ecffea64bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Henrique=20Rodrigues?= Date: Wed, 30 Nov 2022 20:09:57 -0300 Subject: [PATCH 01/10] =?UTF-8?q?Adicionei=20um=20novo=20algor=C3=ADtimo?= =?UTF-8?q?=20de=20ordena=C3=A7=C3=A3o=20no=20arquivo=20Bubblesort.java.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/algoritmos/Bubblesort.java | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/algoritmos/Bubblesort.java diff --git a/src/algoritmos/Bubblesort.java b/src/algoritmos/Bubblesort.java new file mode 100644 index 0000000..b7ef41b --- /dev/null +++ b/src/algoritmos/Bubblesort.java @@ -0,0 +1,41 @@ +package algoritmos; + +import java.io.IOException; + +public class Bubblesort { + + public static void main(String[] args) throws IOException { + + int quantidade = 10000; + int[] vetor = new int[quantidade]; + + for (int i = 0; i < vetor.length; i++) { + vetor[i] = (int) (Math.random()*quantidade); + } + + long tempoInicial = System.currentTimeMillis(); + + bubbleSort(vetor); + + long tempoFinal = System.currentTimeMillis(); + + System.out.println("Executado em = " + (tempoFinal - tempoInicial) + " ms"); + + } + + private static void bubbleSort(int vetor[]){ + boolean troca = true; + int aux; + while (troca) { + troca = false; + for (int i = 0; i < vetor.length - 1; i++) { + if (vetor[i] > vetor[i + 1]) { + aux = vetor[i]; + vetor[i] = vetor[i + 1]; + vetor[i + 1] = aux; + troca = true; + } + } + } + } +} From 3062246a57b9cecc71fa81c2b128634edea12c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Henrique=20Rodrigues?= Date: Wed, 30 Nov 2022 20:15:57 -0300 Subject: [PATCH 02/10] =?UTF-8?q?Adicionei=20o=20'run'=20com=20o=20caminho?= =?UTF-8?q?=20do=20diret=C3=B3rio=20do=20arquivo=20Bubblesort.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37b4d29..cda237c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,4 +13,5 @@ jobs: with: java-version: '17' distribution: 'adopt' - - run: java src/algoritmos/Quicksort.java \ No newline at end of file + - run: java src/algoritmos/Quicksort.java + - run: java src/algoritmos/Bubblesort.java From 27cb1787f836cf65a0eb73cfea7aa0c57050dbf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Henrique=20Rodrigues?= Date: Wed, 30 Nov 2022 20:27:52 -0300 Subject: [PATCH 03/10] Corrigi o arquivo ci.yml. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cda237c..69f6e6c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,4 +14,4 @@ jobs: java-version: '17' distribution: 'adopt' - run: java src/algoritmos/Quicksort.java - - run: java src/algoritmos/Bubblesort.java + - run: java src/algoritmos/Bubblesort.java \ No newline at end of file From d4ee1db7ca9b599ba0d526cfa6384035b9196c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Henrique=20Rodrigues?= Date: Wed, 30 Nov 2022 20:44:00 -0300 Subject: [PATCH 04/10] =?UTF-8?q?Adicionei=20sa=C3=ADda=20de=20dados=20par?= =?UTF-8?q?a=20o=20vetor.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/algoritmos/Bubblesort.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/algoritmos/Bubblesort.java b/src/algoritmos/Bubblesort.java index b7ef41b..334e6a6 100644 --- a/src/algoritmos/Bubblesort.java +++ b/src/algoritmos/Bubblesort.java @@ -9,8 +9,11 @@ public static void main(String[] args) throws IOException { int quantidade = 10000; int[] vetor = new int[quantidade]; + System.out.println("\nVetor: "); for (int i = 0; i < vetor.length; i++) { vetor[i] = (int) (Math.random()*quantidade); + + System.out.print(vetor[i] + " "); } long tempoInicial = System.currentTimeMillis(); @@ -19,7 +22,8 @@ public static void main(String[] args) throws IOException { long tempoFinal = System.currentTimeMillis(); - System.out.println("Executado em = " + (tempoFinal - tempoInicial) + " ms"); + System.out.println("\nExecutado em = " + (tempoFinal - tempoInicial) + " ms"); + } From f97a826012ae28a4135da87bfc2dd22df5f4b1e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Henrique=20Rodrigues?= Date: Wed, 30 Nov 2022 20:48:44 -0300 Subject: [PATCH 05/10] Adicionei gatilho pull_request ao arquivo ci.yml. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 69f6e6c..5806dab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: Java CI -on: [push] +on: [push, pull_request] jobs: build: From 3ed335c8938b9e3c22f0d151aa66945473485f11 Mon Sep 17 00:00:00 2001 From: rcaa Date: Thu, 1 Dec 2022 12:53:41 -0300 Subject: [PATCH 06/10] adicionando computacao de fibonacci --- src/exemplos/Main.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/exemplos/Main.java diff --git a/src/exemplos/Main.java b/src/exemplos/Main.java new file mode 100644 index 0000000..f1e69d6 --- /dev/null +++ b/src/exemplos/Main.java @@ -0,0 +1,18 @@ +package exemplos; + +public class Main { + + public static void main(String[] args) { + // TODO Auto-generated method stub + f(10); + } + + public static long f(int n) { + int x; + if (n < 2) { + return n; + } else { + return f(n - 1) + f(n - 2); + } + } +} From 4ef17c549e64d1b8f026afd3b497f70e8566c26f Mon Sep 17 00:00:00 2001 From: rcaa Date: Thu, 1 Dec 2022 13:14:31 -0300 Subject: [PATCH 07/10] ajeitando o nome da classe do MergeSort --- src/algoritmos/MergeSort.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algoritmos/MergeSort.java b/src/algoritmos/MergeSort.java index a1ad3c3..7e3ac86 100644 --- a/src/algoritmos/MergeSort.java +++ b/src/algoritmos/MergeSort.java @@ -2,7 +2,7 @@ import java.io.IOException; -public class Mergesort { +public class MergeSort { public static void main(String[] args) throws IOException { int quantidade = 10000; From 286305651f1364d2304016f486b7b5496a5e628e Mon Sep 17 00:00:00 2001 From: rcaa Date: Thu, 1 Dec 2022 13:14:57 -0300 Subject: [PATCH 08/10] adicionando metodo para leitura de arquivo --- src/exemplos/Main.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/exemplos/Main.java b/src/exemplos/Main.java index f1e69d6..1b8e78a 100644 --- a/src/exemplos/Main.java +++ b/src/exemplos/Main.java @@ -1,10 +1,15 @@ package exemplos; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + public class Main { public static void main(String[] args) { // TODO Auto-generated method stub f(10); + readFile(""); } public static long f(int n) { @@ -15,4 +20,24 @@ public static long f(int n) { return f(n - 1) + f(n - 2); } } + + public static String readFile(String fileName){ + BufferedReader br; + try { + br = new BufferedReader(new FileReader(fileName)); + final StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + + while (line != null) { + sb.append(line); + sb.append(System.lineSeparator()); + line = br.readLine(); + } + br.close(); + return sb.toString(); + } catch (IOException e) { + e.printStackTrace(); + } + return ""; + } } From 992d024d48fb2f858a4367edb3c137e298f1825f Mon Sep 17 00:00:00 2001 From: rcaa Date: Thu, 1 Dec 2022 13:27:41 -0300 Subject: [PATCH 09/10] adicionando metodo de validacao de string --- src/exemplos/Main.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/exemplos/Main.java b/src/exemplos/Main.java index 1b8e78a..cfe6dbc 100644 --- a/src/exemplos/Main.java +++ b/src/exemplos/Main.java @@ -10,6 +10,7 @@ public static void main(String[] args) { // TODO Auto-generated method stub f(10); readFile(""); + validarString("omnilink"); } public static long f(int n) { @@ -40,4 +41,12 @@ public static String readFile(String fileName){ } return ""; } + + public static boolean validarString(String entrada) { + if (entrada != null && !entrada.equals("") && entrada.length() > 3) { + return true; + } else { + return false; + } + } } From bdb93a7c0cfc2b7304831169851b71e0382497f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Henrique=20Rodrigues?= Date: Thu, 1 Dec 2022 20:58:52 -0300 Subject: [PATCH 10/10] Corriji os problemas indentificados pela plataforma Codacy. --- src/algoritmos/MergeSort.java | 5 ++++- src/algoritmos/Quicksort.java | 4 +++- src/algoritmos/SelectionSort.java | 2 -- src/exemplos/Main.java | 8 ++------ 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/algoritmos/MergeSort.java b/src/algoritmos/MergeSort.java index 7e3ac86..8a9f028 100644 --- a/src/algoritmos/MergeSort.java +++ b/src/algoritmos/MergeSort.java @@ -45,7 +45,10 @@ private static void mergeSort(int[] a, int n) { private static void merge( int[] a, int[] l, int[] r, int left, int right) { - int i = 0, j = 0, k = 0; + int i = 0; + int j = 0; + int k = 0; + while (i < left && j < right) { if (l[i] <= r[j]) { a[k++] = l[i++]; diff --git a/src/algoritmos/Quicksort.java b/src/algoritmos/Quicksort.java index 9f109aa..607945f 100644 --- a/src/algoritmos/Quicksort.java +++ b/src/algoritmos/Quicksort.java @@ -30,7 +30,9 @@ private static void quickSort(int[] vetor, int inicio, int fim) { private static int posicaoPivor(int[] vetor, int inicio, int fim) { int pivo = vetor[inicio]; - int i = inicio + 1, f = fim; + int i = inicio + 1; + int f = fim; + while (i <= f) { if (vetor[i] <= pivo) i++; diff --git a/src/algoritmos/SelectionSort.java b/src/algoritmos/SelectionSort.java index c7d5ef7..c4d1ba7 100644 --- a/src/algoritmos/SelectionSort.java +++ b/src/algoritmos/SelectionSort.java @@ -1,7 +1,5 @@ package algoritmos; -import java.io.IOException; - public class SelectionSort { public static void main(String args[]) { diff --git a/src/exemplos/Main.java b/src/exemplos/Main.java index cfe6dbc..f95585a 100644 --- a/src/exemplos/Main.java +++ b/src/exemplos/Main.java @@ -14,7 +14,6 @@ public static void main(String[] args) { } public static long f(int n) { - int x; if (n < 2) { return n; } else { @@ -43,10 +42,7 @@ public static String readFile(String fileName){ } public static boolean validarString(String entrada) { - if (entrada != null && !entrada.equals("") && entrada.length() > 3) { - return true; - } else { - return false; - } + + return entrada != null && !entrada.equals("") && entrada.length() > 3; } }