Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/c/BinarySearchTree.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Árvore Binária de Busca em C
* Binary Search Tree in C
*
* ( 6 )
* / \
Expand Down
2 changes: 1 addition & 1 deletion src/c/BinaryTree.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <stdio.h>
#include <stdlib.h>

// Essa é uma árvore binária não balanceada.
// This is an unbalanced binary tree.

struct No {

Expand Down
2 changes: 1 addition & 1 deletion src/c/CircularLinkedList.c
Original file line number Diff line number Diff line change
@@ -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)
*
*/

Expand Down
4 changes: 2 additions & 2 deletions src/c/ConnectedComponents.c
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
28 changes: 14 additions & 14 deletions src/c/CountingSort.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include <stdio.h>
#include <stdlib.h>

// 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];

Expand All @@ -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]]--;
Expand All @@ -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]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/c/DoublyLinkedList.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Exemplo Lista Duplamente Encadeada em C
* Example of Doubly Linked List in C
*/

#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion src/c/DynamicQueue.c
Original file line number Diff line number Diff line change
@@ -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 <malloc.h>
Expand Down
2 changes: 1 addition & 1 deletion src/c/DynamicStack.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Pilha Dinâmica utilizando uma Lista Ligada em C
* Dynamic Stack using a Linked List in C
*/

#include <malloc.h>
Expand Down
2 changes: 1 addition & 1 deletion src/c/Factorial.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <stdlib.h>

/*
* 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
*/

Expand Down
6 changes: 3 additions & 3 deletions src/c/FloydWarshall.c
Original file line number Diff line number Diff line change
@@ -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
*
Expand Down
4 changes: 2 additions & 2 deletions src/c/GraphSearch.c
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/c/HamiltonianCycle.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Grafos - CICLO HAMILTONIANO em C
* Graphs - HAMILTONIAN CYCLE in C
*
* -----------------------------------
* | |
Expand Down
100 changes: 50 additions & 50 deletions src/c/InsertionSort.c
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
/*
Algoritmo de ordenação Insertion Sort em C
*/
#include <stdio.h> // Necessário para usar input e output
#include <stdlib.h> // Necessário para usar a função rand()
#include <time.h> // 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 <stdio.h> // Required for input and output
#include <stdlib.h> // Necessário para usar a função rand()
#include <time.h> // 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;
}
6 changes: 3 additions & 3 deletions src/c/LinearSearchSentinel.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
Expand Down
4 changes: 2 additions & 2 deletions src/c/MaxRecursive.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
Expand Down
4 changes: 2 additions & 2 deletions src/c/MergeSort.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/c/MinMaxRecursive.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion src/c/Queue.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Exemplo de implementação de Fila em C
* Example of Queue implementation in C
*/

#include <stdio.h>
Expand Down
4 changes: 2 additions & 2 deletions src/c/SortedLinkedList.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion src/c/Stack.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Exemplo de implementação de Pilha em C - Utiliza Sentinela
* Example of Stack implementation in C - Uses Sentinel
*/

#include <stdio.h>
Expand Down
42 changes: 21 additions & 21 deletions src/c/TowerOfHanoi.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/*
Torre de Hanoi em C
*/
#include <stdio.h>
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 <stdio.h>

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;
}
2 changes: 1 addition & 1 deletion src/c/UnorderedLinkedList.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Exemplo de Lista Ligada Dinâmica Não Ordenada em C
* Example of Unordered Dynamic Linked List in C
*/

#include <malloc.h>
Expand Down