diff --git a/.github/linters/.golangci.yml b/.github/linters/.golangci.yml index a8eddf87..58f73cac 100644 --- a/.github/linters/.golangci.yml +++ b/.github/linters/.golangci.yml @@ -1,4 +1,5 @@ -linters: +version: "2" +formatters: enable: - gofmt - goimports diff --git a/.github/workflows/lint-checker.yml b/.github/workflows/lint-checker.yml index 3897f9ba..be86195d 100644 --- a/.github/workflows/lint-checker.yml +++ b/.github/workflows/lint-checker.yml @@ -15,7 +15,7 @@ jobs: with: fetch-depth: 0 - name: Check Code - uses: super-linter/super-linter@v7.1.0 + uses: super-linter/super-linter@v8.5.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VALIDATE_GO: true diff --git a/src/c/CircularLinkedList.c b/src/c/CircularLinkedList.c index 0593d07c..03f15c5f 100644 --- a/src/c/CircularLinkedList.c +++ b/src/c/CircularLinkedList.c @@ -51,10 +51,9 @@ bool excluir(TIPOCHAVE ch, LISTA *L) { // como endereço de memória, assim a função busca // altera ele, guardando o valor anterior if (aux == NULL) - return false; // Não encontrou - ant->prox = aux->prox; // Nó anterior aponta para o próximo, no caso o próximo - // que o nó a ser excluído está apontando - free(aux); // Libera a memória + return false; + ant->prox = aux->prox; + free(aux); return true; } @@ -67,10 +66,10 @@ void inserir(TIPOCHAVE ch, LISTA *L) { pos = pos->prox; // Vai para o próximo nó } // Quando encontrou a posição correta na ordem crescente - PONT novo_no = (PONT)malloc(sizeof(NO)); // Cria um novo nó - novo_no->chave = ch; // Coloca a chave no nó - novo_no->prox = pos; // Aponta para o próximo nó - ant->prox = novo_no; // Nó anterior aponta para o novo nó + PONT novo_no = (PONT)malloc(sizeof(NO)); + novo_no->chave = ch; + novo_no->prox = pos; + ant->prox = novo_no; } PONT mostrarLista(LISTA L) { @@ -111,4 +110,4 @@ int main() { printf("Valor %d não encontrado.\n", valor); return 0; -} \ No newline at end of file +} diff --git a/src/c/LinearSearchSentinel.c b/src/c/LinearSearchSentinel.c index 37071d8b..6e8d7e1d 100644 --- a/src/c/LinearSearchSentinel.c +++ b/src/c/LinearSearchSentinel.c @@ -19,12 +19,9 @@ int buscaSentinela(int vetor[], int chave) { while (vetor[aux] != chave) // Enquanto não encontrar o valor (chave) incrementa 1 em aux aux++; - if (aux == TAM_VETOR) // Caso o valor de aux seja igual ao tamanho do vetor, - // significa que foi até o final e não encontrou o valor - return -1; // Não encontrou - else // Caso aux seja diferente, significa que encontrou o valor e quebrou o - // laço, o aux é a posição do valor buscado - return aux; // Encontrou + if (aux == TAM_VETOR) + return -1; + return aux; } int main() { diff --git a/src/javascript/BinarySearchTree.js b/src/javascript/BinarySearchTree.js index eaab3152..f83abf29 100644 --- a/src/javascript/BinarySearchTree.js +++ b/src/javascript/BinarySearchTree.js @@ -170,3 +170,27 @@ class BinarySearchTree { } } +function main() { + let tree = new BinarySearchTree(); + + tree.add(1); + tree.add(4); + tree.add(3); + tree.add(5); + tree.add(2); + + tree.preOrderTraversal(); + tree.inOrderTraversal(); + tree.postOrderTraversal(); + + tree.containsElement(3); + tree.remove(3); + tree.containsElement(3); + tree.inOrderTraversal(); + + tree.empty(); + tree.inOrderTraversal(); +} + +main(); + diff --git a/src/javascript/Deque.js b/src/javascript/Deque.js index 67f97812..f0039d82 100644 --- a/src/javascript/Deque.js +++ b/src/javascript/Deque.js @@ -27,4 +27,23 @@ class Deque { let dequeCopy = this.deque.slice(); console.log(dequeCopy.reverse()); } -} \ No newline at end of file +} + +function main() { + let deque = new Deque(); + + deque.addFront(2); + deque.addFront(1); + deque.addFront(0); + + deque.addEnd(3); + deque.addEnd(4); + + deque.removeFront(); + deque.removeEnd(); + + deque.readFromFront(); + deque.readFromEnd(); +} + +main(); diff --git a/src/javascript/DoublyLinkedList.js b/src/javascript/DoublyLinkedList.js index e88af4eb..2e994685 100644 --- a/src/javascript/DoublyLinkedList.js +++ b/src/javascript/DoublyLinkedList.js @@ -103,3 +103,17 @@ class DoublyLinkedList { } } } + +function main() { + let list = new DoublyLinkedList(); + + list.addToFront(2); + list.addToFront(1); + list.addToEnd(3); + + list.readFromFront(); + list.remove(2); + list.readFromEnd(); +} + +main(); diff --git a/src/javascript/LinearSearchSentinel.js b/src/javascript/LinearSearchSentinel.js index cef1e6f7..94278120 100644 --- a/src/javascript/LinearSearchSentinel.js +++ b/src/javascript/LinearSearchSentinel.js @@ -16,10 +16,10 @@ function sentinelSearch(array, wantedValue) { } function main() { - array = [32, 45, 31, 87, 32, 12, 76, 32, 16, 47, 54, 90]; - wantedValue = 54; + let array = [32, 45, 31, 87, 32, 12, 76, 32, 16, 47, 54, 90]; + const wantedValue = 54; - foundIndex = sentinelSearch(array, wantedValue); + const foundIndex = sentinelSearch(array, wantedValue); if (foundIndex >= 0) { console.log(`Value found at index "${foundIndex}".`) diff --git a/src/javascript/MinMaxIterative.js b/src/javascript/MinMaxIterative.js index e105cbd4..ef92e3e4 100644 --- a/src/javascript/MinMaxIterative.js +++ b/src/javascript/MinMaxIterative.js @@ -4,17 +4,15 @@ const MAX_LENGTH = 10; * @param {number[]} vector */ function MinMaxIterative(vector){ - let min = max = vector[0]; + let min = vector[0]; + let max = vector[0]; vector.forEach(value => { if (value > max) max = value; if(value < min) min = value; }); - return { - min, - max - } + return {min, max} } function main(){ @@ -32,4 +30,4 @@ function main(){ console.log(`Min: ${result.min}\nMax: ${result.max}`); } -main(); \ No newline at end of file +main(); diff --git a/src/javascript/Queue.js b/src/javascript/Queue.js index b2f702bd..2bf11755 100644 --- a/src/javascript/Queue.js +++ b/src/javascript/Queue.js @@ -18,4 +18,21 @@ class Queue { empty() { this.queue = []; } -} \ No newline at end of file +} + +function main() { + let queue = new Queue(); + + queue.enqueue(1); + queue.enqueue(2); + queue.enqueue(3); + queue.read(); + + queue.dequeue(); + queue.read(); + + queue.empty(); + queue.read(); +} + +main(); diff --git a/src/javascript/Stack.js b/src/javascript/Stack.js index f337430d..1ec4d8dc 100644 --- a/src/javascript/Stack.js +++ b/src/javascript/Stack.js @@ -18,4 +18,21 @@ class Stack { clear() { this.stack = []; } -} \ No newline at end of file +} + +function main() { + let stack = new Stack(); + + stack.push(1); + stack.push(2); + stack.push(3); + stack.read(); + + stack.pop(); + stack.read(); + + stack.clear(); + stack.read(); +} + +main(); diff --git a/src/python/binary_search.py b/src/python/binary_search.py index acfc880c..481a787b 100644 --- a/src/python/binary_search.py +++ b/src/python/binary_search.py @@ -1,4 +1,4 @@ -""" Recursive Binary Search Algorithm in Python """ +"""Recursive Binary Search Algorithm in Python""" def binary_search(value, vector, left, right): diff --git a/src/python/binary_search_tree.py b/src/python/binary_search_tree.py index 2b7fa910..f295072c 100644 --- a/src/python/binary_search_tree.py +++ b/src/python/binary_search_tree.py @@ -1,4 +1,4 @@ -""" Binary Search Tree in Python """ +"""Binary Search Tree in Python""" class TreeNode: diff --git a/src/python/binary_tree.py b/src/python/binary_tree.py index ede3fa47..4aea0f9b 100644 --- a/src/python/binary_tree.py +++ b/src/python/binary_tree.py @@ -1,4 +1,4 @@ -""" Binary Tree in Python """ +"""Binary Tree in Python""" class Node: diff --git a/src/python/bogosort.py b/src/python/bogosort.py index 90cbd222..938f036c 100644 --- a/src/python/bogosort.py +++ b/src/python/bogosort.py @@ -1,4 +1,4 @@ -""" Implementation of the bogosort algorithm in Python. """ +"""Implementation of the bogosort algorithm in Python.""" import random diff --git a/src/python/bubble_sort.py b/src/python/bubble_sort.py index 7730f855..9a7d3839 100755 --- a/src/python/bubble_sort.py +++ b/src/python/bubble_sort.py @@ -1,4 +1,4 @@ -""" Recursive Bubble Sort in Python """ +"""Recursive Bubble Sort in Python""" def bubble_sort(data, size): diff --git a/src/python/calculate_pi.py b/src/python/calculate_pi.py index 9a7ae1b4..c1c8840e 100644 --- a/src/python/calculate_pi.py +++ b/src/python/calculate_pi.py @@ -1,4 +1,4 @@ -""" Calculating PI in Python """ +"""Calculating PI in Python""" def calculate_pi(number): diff --git a/src/python/circular_linked_list.py b/src/python/circular_linked_list.py index a65b2f61..d6cdf843 100644 --- a/src/python/circular_linked_list.py +++ b/src/python/circular_linked_list.py @@ -1,4 +1,4 @@ -""" Implementation of a circular linked list in Python """ +"""Implementation of a circular linked list in Python""" import unittest diff --git a/src/python/comb_sort.py b/src/python/comb_sort.py index 8adde32f..b9b59a0e 100644 --- a/src/python/comb_sort.py +++ b/src/python/comb_sort.py @@ -1,4 +1,4 @@ -""" Comb Sort in Python """ +"""Comb Sort in Python""" def comb_sort(arr: list) -> list: diff --git a/src/python/counting_sort.py b/src/python/counting_sort.py index fec1bae6..f8409ff2 100644 --- a/src/python/counting_sort.py +++ b/src/python/counting_sort.py @@ -1,4 +1,4 @@ -""" Counting sort in Python """ +"""Counting sort in Python""" import random diff --git a/src/python/exponentiation.py b/src/python/exponentiation.py index e54f9f38..ab86e273 100644 --- a/src/python/exponentiation.py +++ b/src/python/exponentiation.py @@ -1,4 +1,4 @@ -""" Iterative exponentiation algorithm """ +"""Iterative exponentiation algorithm""" def exponentiation(base, exponent): diff --git a/src/python/exponentiation_recursive.py b/src/python/exponentiation_recursive.py index 1db76fd2..92173eb6 100644 --- a/src/python/exponentiation_recursive.py +++ b/src/python/exponentiation_recursive.py @@ -1,4 +1,4 @@ -""" Recursive exponentiation algorithm """ +"""Recursive exponentiation algorithm""" def exponentiation_recursive(base, exponent): diff --git a/src/python/factorial.py b/src/python/factorial.py index 48ef04c4..d3c3b616 100644 --- a/src/python/factorial.py +++ b/src/python/factorial.py @@ -1,4 +1,4 @@ -""" Iterative factorial algorithm """ +"""Iterative factorial algorithm""" def factorial(num): diff --git a/src/python/factorial_recursive.py b/src/python/factorial_recursive.py index d497d22d..68ea8322 100644 --- a/src/python/factorial_recursive.py +++ b/src/python/factorial_recursive.py @@ -1,4 +1,4 @@ -""" Recursive factorial algorithm """ +"""Recursive factorial algorithm""" def factorial_recursive(num): diff --git a/src/python/heap_sort.py b/src/python/heap_sort.py index 4a6e7fa6..1bf1f4ef 100644 --- a/src/python/heap_sort.py +++ b/src/python/heap_sort.py @@ -1,4 +1,4 @@ -""" Heap sort algorithm implementation """ +"""Heap sort algorithm implementation""" def heap_sort(data): diff --git a/src/python/insertion_sort.py b/src/python/insertion_sort.py index b97eef95..35bb63a0 100644 --- a/src/python/insertion_sort.py +++ b/src/python/insertion_sort.py @@ -1,4 +1,4 @@ -""" Insertion Sort in Python (Iterative and Recursive) """ +"""Insertion Sort in Python (Iterative and Recursive)""" def insertion_sort_iterative(vector): diff --git a/src/python/linear_search_sentinel.py b/src/python/linear_search_sentinel.py index 2ecde03f..797e5231 100644 --- a/src/python/linear_search_sentinel.py +++ b/src/python/linear_search_sentinel.py @@ -1,4 +1,4 @@ -""" Implementacao do algoritmo de busca sentinela """ +"""Implementacao do algoritmo de busca sentinela""" def busca_sentinela(list_to_search, value): diff --git a/src/python/lista_encadeada_desordenada.py b/src/python/lista_encadeada_desordenada.py index 3830c77a..f69306c6 100644 --- a/src/python/lista_encadeada_desordenada.py +++ b/src/python/lista_encadeada_desordenada.py @@ -1,4 +1,4 @@ -""" Implementação de uma lista encadeada desordenada """ +"""Implementação de uma lista encadeada desordenada""" class Node: diff --git a/src/python/lz77.py b/src/python/lz77.py index fba93b12..59088f99 100644 --- a/src/python/lz77.py +++ b/src/python/lz77.py @@ -248,7 +248,7 @@ def compress(self, input_data): if match: # o PAR LZ é constituido da bit flag 1, seguida por 12 bits # para distância e 4 bits para o tamanho da ocorrência. - (best_match_distance, best_match_length) = match + best_match_distance, best_match_length = match # Primeiro nibble da distancia x = (best_match_distance >> 0x4).to_bytes(1, self.ENDIAN_TYPE) # Segundo nibble da distancia acrescido do tamanho diff --git a/src/python/merge_sort.py b/src/python/merge_sort.py index ef460bd5..fed6c61f 100644 --- a/src/python/merge_sort.py +++ b/src/python/merge_sort.py @@ -1,4 +1,4 @@ -""" Merge sort algorithm implementation """ +"""Merge sort algorithm implementation""" def merge_sort(data): diff --git a/src/python/min_max_recursive.py b/src/python/min_max_recursive.py index a2ede7e9..d1cd4f25 100644 --- a/src/python/min_max_recursive.py +++ b/src/python/min_max_recursive.py @@ -1,4 +1,4 @@ -""" Implementação do algoritmo de máximo e mínimo com recursão """ +"""Implementação do algoritmo de máximo e mínimo com recursão""" def max_min(vetor, minimo, maximo, indice): diff --git a/src/python/quick_sort.py b/src/python/quick_sort.py index a1015cdd..6ec71a5e 100644 --- a/src/python/quick_sort.py +++ b/src/python/quick_sort.py @@ -1,4 +1,4 @@ -""" Quick Sort in Python """ +"""Quick Sort in Python""" def swap(a_list, pos1, pos2): diff --git a/src/python/selection_sort.py b/src/python/selection_sort.py index f4e1b947..bbc589c6 100644 --- a/src/python/selection_sort.py +++ b/src/python/selection_sort.py @@ -1,4 +1,4 @@ -""" Implementação de um algoritmo de selection sort com recursão """ +"""Implementação de um algoritmo de selection sort com recursão""" def selection_sort(vetor, indice): diff --git a/src/python/sorted_linked_list.py b/src/python/sorted_linked_list.py index 0da4ca59..49b2bc43 100644 --- a/src/python/sorted_linked_list.py +++ b/src/python/sorted_linked_list.py @@ -1,4 +1,4 @@ -""" Lista Sequencial Dinamica e Ordenada """ +"""Lista Sequencial Dinamica e Ordenada""" import random diff --git a/src/scala/Dijkstra.scala b/src/scala/Dijkstra.scala index a8ab6ae4..8334ecfc 100644 --- a/src/scala/Dijkstra.scala +++ b/src/scala/Dijkstra.scala @@ -22,7 +22,7 @@ case class Graph(edges: List[Edge]) { @tailrec final def dijkstra(start: Vertex, pathComposition: Path = EmptyPath): Path = { - val startEdges: Seq[Edge] = edges.filter(_.from == start).sorted + val startEdges: Seq[Edge] = edges.filter(_.from == start).sorted val smallestDistance: Option[Edge] = startEdges .filter(e => !pathComposition.edges.map(_.from).contains(e.to)) .headOption @@ -41,7 +41,7 @@ case class Graph(edges: List[Edge]) { object Main extends App { val startA: Vertex = Vertex("A") - val graph: Graph = Graph( + val graph: Graph = Graph( edges = List( Edge(from = Vertex("A"), to = Vertex("B"), distance = 1), Edge(from = Vertex("A"), to = Vertex("C"), distance = 4),