diff --git a/src/c/BinarySearchTree.c b/src/c/BinarySearchTree.c index bce19184..8a4ffc9d 100644 --- a/src/c/BinarySearchTree.c +++ b/src/c/BinarySearchTree.c @@ -1,5 +1,5 @@ /* - * Árvore Binária de Busca em C + * Binary Search Tree in C * * ( 6 ) * / \ diff --git a/src/c/BinaryTree.c b/src/c/BinaryTree.c index b1b6a162..154769e4 100644 --- a/src/c/BinaryTree.c +++ b/src/c/BinaryTree.c @@ -1,7 +1,7 @@ #include #include -// Essa é uma árvore binária não balanceada. +// This is an unbalanced binary tree. struct No { diff --git a/src/c/CircularLinkedList.c b/src/c/CircularLinkedList.c index 03f15c5f..9877cdc3 100644 --- a/src/c/CircularLinkedList.c +++ b/src/c/CircularLinkedList.c @@ -1,6 +1,6 @@ /* * - * Lista Ligada com Nó Cabeça, Circular e Ordenada (Implementação Dinâmica) + * Linked List with Head Node, Circular and Sorted (Dynamic Implementation) * */ diff --git a/src/c/ConnectedComponents.c b/src/c/ConnectedComponents.c index 122f8575..f8276771 100644 --- a/src/c/ConnectedComponents.c +++ b/src/c/ConnectedComponents.c @@ -1,7 +1,7 @@ /* * - * Grafos - Algoritmo para calcular o número de componentes conexos em um - *determinado Grafo + * Graphs - Algorithm to calculate the number of connected components in a + *given Graph * * GRAFO * (0) (1)-------------(4)---------------(5) diff --git a/src/c/CountingSort.c b/src/c/CountingSort.c index bebad0e8..823e20e7 100644 --- a/src/c/CountingSort.c +++ b/src/c/CountingSort.c @@ -1,11 +1,11 @@ #include #include -// CountingSort - Ordenação por Contagem - Matheus Martins Batista - -// Universidade Federal de Itajuba - 2021 +// CountingSort - Sorting by Counting - Matheus Martins Batista - +// Federal University of Itajuba - 2021 -// Necessário encontrar o maior elemento para alocar o vetor auxiliar de -// contagem +// Need to find the largest element to allocate the auxiliary counting +// array int findMax(int *arr, int tam) { int max = arr[0]; @@ -18,26 +18,26 @@ int findMax(int *arr, int tam) { return max; } -// Ordena os valores presentes em A e armazena em B +// Sorts the values present in A and stores them in B void countingSort(int *arrA, int *arrB, int tam) { - // Vetor de contagem terá a frequência que um número aparece no vetor - // deve-se setar 0 para todos os elementos ou usar calloc + // Count array will have the frequency that a number appears in the array + // must set 0 for all elements or use calloc int max = findMax(arrA, tam); int *count = calloc(max + 1, sizeof(int)); - // Frequência que determinado valor aparece no vetor + // Frequency that a given value appears in the array for (int i = 0; i < tam; i++) { count[arrA[i]]++; } - // Acumulativo da frequência dos valores menores que um elemento i do vetor - // original (A) + // Cumulative frequency of values less than element i of the original + // array (A) for (int i = 1; i <= max; i++) { count[i] += count[i - 1]; } - // Percorrer o vetor original com início no último elemento, subtituindo os - // indices nos elementos do vetor count e decrescendo a cada atribuição + // Traverse the original array starting from the last element, replacing + // indices in the count array elements and decrementing with each assignment for (int i = tam - 1; i >= 0; i--) { arrB[count[arrA[i]] - 1] = arrA[i]; count[arrA[i]]--; @@ -50,14 +50,14 @@ int main() { arrA = malloc(tam * sizeof(int)); arrB = calloc(tam, sizeof(int)); - // Popular vetor A + // Populate array A srand(48 + tam); for (int j = 0; j < tam; j++) arrA[j] = rand() % 100; countingSort(arrA, arrB, tam); - printf("Vetor ordenado: "); + printf("Sorted array: "); for (int i = 0; i < tam; i++) { printf("%d ", arrB[i]); } diff --git a/src/c/DoublyLinkedList.c b/src/c/DoublyLinkedList.c index 7be11ee4..537bfe7b 100644 --- a/src/c/DoublyLinkedList.c +++ b/src/c/DoublyLinkedList.c @@ -1,5 +1,5 @@ /* - * Exemplo Lista Duplamente Encadeada em C + * Example of Doubly Linked List in C */ #include diff --git a/src/c/DynamicQueue.c b/src/c/DynamicQueue.c index 074aebc6..9699a01b 100644 --- a/src/c/DynamicQueue.c +++ b/src/c/DynamicQueue.c @@ -1,5 +1,5 @@ /* - * Implementação de uma Estrutura de Fila Dinâmica Ligada/Encadeada em C + * Implementation of a Dynamic Linked/Chained Queue Structure in C */ #include diff --git a/src/c/DynamicStack.c b/src/c/DynamicStack.c index 4e63e575..8ee0d403 100644 --- a/src/c/DynamicStack.c +++ b/src/c/DynamicStack.c @@ -1,5 +1,5 @@ /* - * Pilha Dinâmica utilizando uma Lista Ligada em C + * Dynamic Stack using a Linked List in C */ #include diff --git a/src/c/Factorial.c b/src/c/Factorial.c index bed39222..b4fee9fd 100644 --- a/src/c/Factorial.c +++ b/src/c/Factorial.c @@ -2,7 +2,7 @@ #include /* - * Exemplos de função para retornar o fatorial de um número n + * Examples of functions to return the factorial of a number n * função recursiva */ diff --git a/src/c/FloydWarshall.c b/src/c/FloydWarshall.c index 1ce22edc..b384e676 100644 --- a/src/c/FloydWarshall.c +++ b/src/c/FloydWarshall.c @@ -1,8 +1,8 @@ /* - * Grafos - Algoritmo de Floyd-Warshall em C - * Complexidade: Teta de vértices ao cubo = Teta(n^3) + * Graphs - Floyd-Warshall Algorithm in C + * Complexity: Theta of vertices cubed = Theta(n^3) * - * Encontra o caminho de todos para todos os vértices + * Finds the path from all to all vertices * * Grafo com 5 vértices e 6 arestas * diff --git a/src/c/GraphSearch.c b/src/c/GraphSearch.c index 7679dce2..47023948 100644 --- a/src/c/GraphSearch.c +++ b/src/c/GraphSearch.c @@ -1,7 +1,7 @@ /* * - * Grafos - Implementação de uma estrutura de Grafo não dirigido em C - * Métodos de Busca: Busca em Profundidade e Busca em Largura + * Graphs - Implementation of an Undirected Graph structure in C + * Search Methods: Depth-First Search and Breadth-First Search * * * (A)---------------(B)-------------(E)---------------(F) diff --git a/src/c/HamiltonianCycle.c b/src/c/HamiltonianCycle.c index aea872f6..11b4776a 100644 --- a/src/c/HamiltonianCycle.c +++ b/src/c/HamiltonianCycle.c @@ -1,6 +1,6 @@ /* * - * Grafos - CICLO HAMILTONIANO em C + * Graphs - HAMILTONIAN CYCLE in C * * ----------------------------------- * | | diff --git a/src/c/InsertionSort.c b/src/c/InsertionSort.c index 5605bd91..0cfc2b05 100644 --- a/src/c/InsertionSort.c +++ b/src/c/InsertionSort.c @@ -1,51 +1,51 @@ -/* -Algoritmo de ordenação Insertion Sort em C -*/ - -#include // Necessário para usar input e output -#include // Necessário para usar a função rand() -#include // Necessário para inicializar a semente de números aleatórios - -// Definimos a função insertion_sort que recebe como argumento o vetor a ser -// ordenado e seu tamanho n -void insertion_sort(int arr[], int n) { - int i, j, key; - // Percorremos todos os elementos do vetor a partir do segundo elemento - for (i = 1; i < n; i++) { - // Armazenamos o valor do elemento atual em key - key = arr[i]; - // Inicializamos o índice j como o elemento anterior ao elemento atual - j = i - 1; - // Enquanto j é maior ou igual a 0 e o elemento atual é menor do que o - // elemento na posição j do vetor, movemos o elemento na posição j uma - // posição para a direita e decrementamos j - while (j >= 0 && arr[j] > key) { - arr[j + 1] = arr[j]; - j = j - 1; - } - // Quando o loop interno termina, colocamos o elemento atual em sua posição - // correta - arr[j + 1] = key; - } -} - -// Função principal -int main() { - int i, n, arr[100]; - srand(time(NULL)); // Inicializa a semente de números aleatórios - printf("Entre com o numero de elementos no vetor: "); - scanf("%d", &n); - printf("Vetor de entrada:\n"); - for (i = 0; i < n; i++) { - arr[i] = rand() % 100; // Gera um valor aleatório entre 0 e 99 - printf("%d ", arr[i]); // Imprime o valor gerado - } - printf("\n"); - insertion_sort(arr, n); - printf("Vetor ordenado em ordem crescente:\n"); - for (i = 0; i < n; i++) { - printf("%d ", arr[i]); - } - printf("\n"); - return 0; +/* +Insertion Sort algorithm in C +*/ + +#include // Required for input and output +#include // Necessário para usar a função rand() +#include // Necessário para inicializar a semente de números aleatórios + +// Definimos a função insertion_sort que recebe como argumento o vetor a ser +// ordenado e seu tamanho n +void insertion_sort(int arr[], int n) { + int i, j, key; + // Percorremos todos os elementos do vetor a partir do segundo elemento + for (i = 1; i < n; i++) { + // Armazenamos o valor do elemento atual em key + key = arr[i]; + // Inicializamos o índice j como o elemento anterior ao elemento atual + j = i - 1; + // Enquanto j é maior ou igual a 0 e o elemento atual é menor do que o + // elemento na posição j do vetor, movemos o elemento na posição j uma + // posição para a direita e decrementamos j + while (j >= 0 && arr[j] > key) { + arr[j + 1] = arr[j]; + j = j - 1; + } + // Quando o loop interno termina, colocamos o elemento atual em sua posição + // correta + arr[j + 1] = key; + } +} + +// Função principal +int main() { + int i, n, arr[100]; + srand(time(NULL)); // Inicializa a semente de números aleatórios + printf("Entre com o numero de elementos no vetor: "); + scanf("%d", &n); + printf("Vetor de entrada:\n"); + for (i = 0; i < n; i++) { + arr[i] = rand() % 100; // Gera um valor aleatório entre 0 e 99 + printf("%d ", arr[i]); // Imprime o valor gerado + } + printf("\n"); + insertion_sort(arr, n); + printf("Vetor ordenado em ordem crescente:\n"); + for (i = 0; i < n; i++) { + printf("%d ", arr[i]); + } + printf("\n"); + return 0; } \ No newline at end of file diff --git a/src/c/LinearSearchSentinel.c b/src/c/LinearSearchSentinel.c index 6e8d7e1d..750fcbb1 100644 --- a/src/c/LinearSearchSentinel.c +++ b/src/c/LinearSearchSentinel.c @@ -1,7 +1,7 @@ /* - * Exemplo de Busca Sentinela em C - * Objetivo: Encontrar um valor em um vetor sem precisar testar todos os - *valores dentro do laço + * Example of Sentinel Search in C + * Objective: Find a value in an array without testing all + *values inside the loop */ #include diff --git a/src/c/MaxRecursive.c b/src/c/MaxRecursive.c index b173c575..b189bad6 100644 --- a/src/c/MaxRecursive.c +++ b/src/c/MaxRecursive.c @@ -1,6 +1,6 @@ /* - * Exemplos de funções para achar maior número de um vetor - * As 3 são recursivas porém apenas a MaxDC utiliza divisão e conquista + * Examples of functions to find the largest number in an array + * All 3 are recursive but only MaxDC uses divide and conquer */ #include diff --git a/src/c/MergeSort.c b/src/c/MergeSort.c index f3470e26..28977b5c 100644 --- a/src/c/MergeSort.c +++ b/src/c/MergeSort.c @@ -1,7 +1,7 @@ /* - * Exemplo de Ordenação utilizando Merge Sort + * Example of Sorting using Merge Sort * - * Dividir para conquistar: + * Divide and conquer: * * Dividir: Dividir os dados em subsequências pequenas; * Conquistar: Classificar as duas metades recursivamente aplicando o merge diff --git a/src/c/MinMaxRecursive.c b/src/c/MinMaxRecursive.c index dcbdb235..399419bd 100644 --- a/src/c/MinMaxRecursive.c +++ b/src/c/MinMaxRecursive.c @@ -1,7 +1,7 @@ /* - * Exemplo de algoritmo recursivo. - * Objetivo: encontrar o valor máximo e mínimo em um vetor, utilizando - *recursividade + * Example of recursive algorithm. + * Objective: find the maximum and minimum value in an array, using + *recursion */ #include diff --git a/src/c/Queue.c b/src/c/Queue.c index 35ad7a8c..662ceb06 100644 --- a/src/c/Queue.c +++ b/src/c/Queue.c @@ -1,5 +1,5 @@ /* - * Exemplo de implementação de Fila em C + * Example of Queue implementation in C */ #include diff --git a/src/c/SortedLinkedList.c b/src/c/SortedLinkedList.c index 8fc5b4ff..973ae852 100644 --- a/src/c/SortedLinkedList.c +++ b/src/c/SortedLinkedList.c @@ -1,6 +1,6 @@ /* - * Exemplo de implementação de Lista Sequencial Ordenada em C - Utilizando - *sentinela + * Example of Sorted Sequential List implementation in C - Using + *sentinel */ #include diff --git a/src/c/Stack.c b/src/c/Stack.c index e3b290dd..41988b64 100644 --- a/src/c/Stack.c +++ b/src/c/Stack.c @@ -1,5 +1,5 @@ /* - * Exemplo de implementação de Pilha em C - Utiliza Sentinela + * Example of Stack implementation in C - Uses Sentinel */ #include diff --git a/src/c/TowerOfHanoi.c b/src/c/TowerOfHanoi.c index 91ec0226..d28025d0 100644 --- a/src/c/TowerOfHanoi.c +++ b/src/c/TowerOfHanoi.c @@ -1,21 +1,21 @@ -/* -Torre de Hanoi em C -*/ - -#include - -void hanoi(int pino0, int pino2, int pino1, int discos) { - if (discos == 1) - printf("Move de %i para %i\n", pino0, pino2); - - else { - hanoi(pino0, pino1, pino2, discos - 1); - hanoi(pino0, pino2, pino1, 1); - hanoi(pino1, pino2, pino0, discos - 1); - } -} - -int main() { - hanoi(0, 2, 1, 3); - return 0; -} +/* +Tower of Hanoi in C +*/ + +#include + +void hanoi(int pino0, int pino2, int pino1, int discos) { + if (discos == 1) + printf("Move de %i para %i\n", pino0, pino2); + + else { + hanoi(pino0, pino1, pino2, discos - 1); + hanoi(pino0, pino2, pino1, 1); + hanoi(pino1, pino2, pino0, discos - 1); + } +} + +int main() { + hanoi(0, 2, 1, 3); + return 0; +} diff --git a/src/c/UnorderedLinkedList.c b/src/c/UnorderedLinkedList.c index cc3b0cfb..e73dbf6e 100644 --- a/src/c/UnorderedLinkedList.c +++ b/src/c/UnorderedLinkedList.c @@ -1,5 +1,5 @@ /* - * Exemplo de Lista Ligada Dinâmica Não Ordenada em C + * Example of Unordered Dynamic Linked List in C */ #include