Skip to content
Merged
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: 2 additions & 1 deletion .github/linters/.golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
linters:
version: "2"
formatters:
enable:
- gofmt
- goimports
2 changes: 1 addition & 1 deletion .github/workflows/lint-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions src/c/CircularLinkedList.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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) {
Expand Down Expand Up @@ -111,4 +110,4 @@ int main() {
printf("Valor %d não encontrado.\n", valor);

return 0;
}
}
9 changes: 3 additions & 6 deletions src/c/LinearSearchSentinel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
24 changes: 24 additions & 0 deletions src/javascript/BinarySearchTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

21 changes: 20 additions & 1 deletion src/javascript/Deque.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,23 @@ class Deque {
let dequeCopy = this.deque.slice();
console.log(dequeCopy.reverse());
}
}
}

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();
14 changes: 14 additions & 0 deletions src/javascript/DoublyLinkedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
6 changes: 3 additions & 3 deletions src/javascript/LinearSearchSentinel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}".`)
Expand Down
10 changes: 4 additions & 6 deletions src/javascript/MinMaxIterative.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand All @@ -32,4 +30,4 @@ function main(){
console.log(`Min: ${result.min}\nMax: ${result.max}`);
}

main();
main();
19 changes: 18 additions & 1 deletion src/javascript/Queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,21 @@ class Queue {
empty() {
this.queue = [];
}
}
}

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();
19 changes: 18 additions & 1 deletion src/javascript/Stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,21 @@ class Stack {
clear() {
this.stack = [];
}
}
}

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();
2 changes: 1 addition & 1 deletion src/python/binary_search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Recursive Binary Search Algorithm in Python """
"""Recursive Binary Search Algorithm in Python"""


def binary_search(value, vector, left, right):
Expand Down
2 changes: 1 addition & 1 deletion src/python/binary_search_tree.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Binary Search Tree in Python """
"""Binary Search Tree in Python"""


class TreeNode:
Expand Down
2 changes: 1 addition & 1 deletion src/python/binary_tree.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Binary Tree in Python """
"""Binary Tree in Python"""


class Node:
Expand Down
2 changes: 1 addition & 1 deletion src/python/bogosort.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Implementation of the bogosort algorithm in Python. """
"""Implementation of the bogosort algorithm in Python."""

import random

Expand Down
2 changes: 1 addition & 1 deletion src/python/bubble_sort.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Recursive Bubble Sort in Python """
"""Recursive Bubble Sort in Python"""


def bubble_sort(data, size):
Expand Down
2 changes: 1 addition & 1 deletion src/python/calculate_pi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Calculating PI in Python """
"""Calculating PI in Python"""


def calculate_pi(number):
Expand Down
2 changes: 1 addition & 1 deletion src/python/circular_linked_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Implementation of a circular linked list in Python """
"""Implementation of a circular linked list in Python"""

import unittest

Expand Down
2 changes: 1 addition & 1 deletion src/python/comb_sort.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Comb Sort in Python """
"""Comb Sort in Python"""


def comb_sort(arr: list) -> list:
Expand Down
2 changes: 1 addition & 1 deletion src/python/counting_sort.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Counting sort in Python """
"""Counting sort in Python"""

import random

Expand Down
2 changes: 1 addition & 1 deletion src/python/exponentiation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Iterative exponentiation algorithm """
"""Iterative exponentiation algorithm"""


def exponentiation(base, exponent):
Expand Down
2 changes: 1 addition & 1 deletion src/python/exponentiation_recursive.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Recursive exponentiation algorithm """
"""Recursive exponentiation algorithm"""


def exponentiation_recursive(base, exponent):
Expand Down
2 changes: 1 addition & 1 deletion src/python/factorial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Iterative factorial algorithm """
"""Iterative factorial algorithm"""


def factorial(num):
Expand Down
2 changes: 1 addition & 1 deletion src/python/factorial_recursive.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Recursive factorial algorithm """
"""Recursive factorial algorithm"""


def factorial_recursive(num):
Expand Down
2 changes: 1 addition & 1 deletion src/python/heap_sort.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Heap sort algorithm implementation """
"""Heap sort algorithm implementation"""


def heap_sort(data):
Expand Down
2 changes: 1 addition & 1 deletion src/python/insertion_sort.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Insertion Sort in Python (Iterative and Recursive) """
"""Insertion Sort in Python (Iterative and Recursive)"""


def insertion_sort_iterative(vector):
Expand Down
2 changes: 1 addition & 1 deletion src/python/linear_search_sentinel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Implementacao do algoritmo de busca sentinela """
"""Implementacao do algoritmo de busca sentinela"""


def busca_sentinela(list_to_search, value):
Expand Down
2 changes: 1 addition & 1 deletion src/python/lista_encadeada_desordenada.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Implementação de uma lista encadeada desordenada """
"""Implementação de uma lista encadeada desordenada"""


class Node:
Expand Down
2 changes: 1 addition & 1 deletion src/python/lz77.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/python/merge_sort.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Merge sort algorithm implementation """
"""Merge sort algorithm implementation"""


def merge_sort(data):
Expand Down
2 changes: 1 addition & 1 deletion src/python/min_max_recursive.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/python/quick_sort.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Quick Sort in Python """
"""Quick Sort in Python"""


def swap(a_list, pos1, pos2):
Expand Down
2 changes: 1 addition & 1 deletion src/python/selection_sort.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/python/sorted_linked_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Lista Sequencial Dinamica e Ordenada """
"""Lista Sequencial Dinamica e Ordenada"""

import random

Expand Down
4 changes: 2 additions & 2 deletions src/scala/Dijkstra.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down