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/15] =?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/15] =?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 8c7d8e8d240b7a28a992d5b185503b746b30745e Mon Sep 17 00:00:00 2001 From: cefanys Date: Wed, 30 Nov 2022 20:25:39 -0300 Subject: [PATCH 03/15] =?UTF-8?q?nova=20implementa=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/algoritmos/SelectionSortExample.java | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/algoritmos/SelectionSortExample.java diff --git a/src/algoritmos/SelectionSortExample.java b/src/algoritmos/SelectionSortExample.java new file mode 100644 index 0000000..61248e7 --- /dev/null +++ b/src/algoritmos/SelectionSortExample.java @@ -0,0 +1,38 @@ +package algoritmos; + +public class SelectionSortExample { + + public static void main(String a[]){ + int quantidade = 10000; + int[] arr1 = new int[quantidade]; + + System.out.println("Before Selection Sort"); + for (int i = 0; i < arr1.length; i++) { + arr1[i] = (int) (Math.random() * quantidade); + System.out.print(arr1[i]+" "); + } + System.out.println(); + + selectionSort(arr1);//sorting array using selection sort + + System.out.println("After Selection Sort"); + for (int i = 0; i < arr1.length; i++) { + System.out.print(arr1[i]+" "); + } + } + + public static void selectionSort(int[] arr){ + for (int i = 0; i < arr.length - 1; i++) + { + int index = i; + for (int j = i + 1; j < arr.length; j++){ + if (arr[j] < arr[index]){ + index = j;//searching for lowest index + } + } + int smallerNumber = arr[index]; + arr[index] = arr[i]; + arr[i] = smallerNumber; + } + } +} 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 04/15] 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 ac8dc8d7258fdcb5a26c0ba7e7fb07aff3336833 Mon Sep 17 00:00:00 2001 From: cefanys Date: Wed, 30 Nov 2022 20:29:12 -0300 Subject: [PATCH 05/15] =?UTF-8?q?altera=C3=A7=C3=B5es=20do=20ci.yml?= 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..0fa3cb3 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/SelectionSortExample.java From ac9bb984cd0321a4f25a4670511c1d645462e8d5 Mon Sep 17 00:00:00 2001 From: cefanys Date: Wed, 30 Nov 2022 20:35:43 -0300 Subject: [PATCH 06/15] =?UTF-8?q?altera=C3=A7=C3=B5es=20do=20ci.yml=20-=20?= =?UTF-8?q?correcao=20linha=20no=20arquivo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .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 0fa3cb3..42b005a 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/SelectionSortExample.java + - run: java src/algoritmos/SelectionSortExample.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 07/15] =?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 bd4b240e6d91f0b1f4332e25e7b758cf85ee449a Mon Sep 17 00:00:00 2001 From: cefanys Date: Wed, 30 Nov 2022 20:46:01 -0300 Subject: [PATCH 08/15] =?UTF-8?q?altera=C3=A7=C3=B5es=20do=20ci.yml=20-=20?= =?UTF-8?q?inclusao=20de=20gatilho=20para=20pull=5Frequest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .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 42b005a..9dd3539 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 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 09/15] 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 10/15] 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 11/15] 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 12/15] 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 13/15] 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 2a1708e49423a7dddc31d9efcdc5d5f5c304fc25 Mon Sep 17 00:00:00 2001 From: cefanys Date: Thu, 1 Dec 2022 20:44:42 -0300 Subject: [PATCH 14/15] correcoes indicadas pelo codacy --- src/algoritmos/MergeSort.java | 4 +++- src/algoritmos/Quicksort.java | 3 ++- src/algoritmos/SelectionSort.java | 1 - 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/algoritmos/MergeSort.java b/src/algoritmos/MergeSort.java index 7e3ac86..c25eead 100644 --- a/src/algoritmos/MergeSort.java +++ b/src/algoritmos/MergeSort.java @@ -45,7 +45,9 @@ 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..2699a48 100644 --- a/src/algoritmos/Quicksort.java +++ b/src/algoritmos/Quicksort.java @@ -30,7 +30,8 @@ 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..15f4036 100644 --- a/src/algoritmos/SelectionSort.java +++ b/src/algoritmos/SelectionSort.java @@ -1,6 +1,5 @@ package algoritmos; -import java.io.IOException; public class SelectionSort { From 6b077b086abdc0895643917ccbdfda1c007f4fc4 Mon Sep 17 00:00:00 2001 From: cefanys Date: Thu, 1 Dec 2022 20:55:55 -0300 Subject: [PATCH 15/15] correcoes indicadas pelo codacy, classe main --- src/exemplos/Main.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/exemplos/Main.java b/src/exemplos/Main.java index cfe6dbc..39d0aea 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,6 @@ 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) } }