Skip to content

Commit

Permalink
Merge branch 'kelvins:main' into countingSort/in-js
Browse files Browse the repository at this point in the history
  • Loading branch information
JMJ2312 authored Nov 13, 2023
2 parents 15a14a9 + 4994418 commit 8e90dbb
Show file tree
Hide file tree
Showing 94 changed files with 2,119 additions and 988 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Before opening a Pull Request, please read the following items:
1. Make sure you have read the [CONTRIBUTING](../CONTRIBUTING.md) guidelines
2. Make sure no other PR is implementing the same change
3. Make sure the Continuous Integration workflows (Github Actions) are all passing
4. If in doubt about how to approach another contributor, read our [CODE OF CONDUCT](../CODE-OF-CONDUCT.md) guidelines
4. If in doubt about how to approach another contributor, read our [CODE OF CONDUCT](../CODE_OF_CONDUCT.md) guidelines

<!-- Remove the above section before opening the pull request -->

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Before you start contributing, please take a moment to review this document to u

## Code of Conduct

We have adopted a [Code of Conduct](./CODE-OF-CONDUCT.md) that we expect all community members to follow. Please make sure to review and adhere to it in all interactions within our community.
We have adopted a [Code of Conduct](./CODE_OF_CONDUCT.md) that we expect all community members to follow. Please make sure to review and adhere to it in all interactions within our community.

## How Can I Contribute?

Expand All @@ -28,7 +28,7 @@ If you encounter an issue or have a feature request, please follow these steps:

Before you start working on a contribution, please keep in mind the following guidelines:

- Adhere to our [Code of Conduct](./CODE-OF-CONDUCT.md).
- Adhere to our [Code of Conduct](./CODE_OF_CONDUCT.md).
- Respect and follow existing project coding standards.
- Write clear and concise commit messages.
- Test your changes thoroughly.
Expand Down
254 changes: 185 additions & 69 deletions README.md

Large diffs are not rendered by default.

99 changes: 0 additions & 99 deletions src/c/AlgoritmoDijkstra.c

This file was deleted.

43 changes: 43 additions & 0 deletions src/c/BinarySearch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include<stdio.h>

int BinarySearch(int array[], int size, int value) {
int start = 0;
int end = size - 1;
int middle = end / 2;

while (start < end && array[middle] != value) {
// new start
if (value > array[middle])
start = middle + 1;

// new end
if (value < array[middle])
end = middle - 1;

// new middle
middle = (start + end) / 2;
}

if (array[middle] == value)
return middle;

return -1;
}

int main() {
int value;
int array[] = {1, 5, 10, 12, 18, 22, 87, 90, 112, 129};
size_t size = sizeof(array) / sizeof(array[0]);

printf("Please provide the number you want to value for: ");
scanf("%d", &value);

int pos = BinarySearch(array, size, value);

if (pos != -1)
printf("Found in position = %d.\nValue = %d\n", pos, array[pos]);
else
printf("Not found\n");

return 0;
}
1 change: 0 additions & 1 deletion src/c/ArvoreBinariaDeBusca.c → src/c/BinarySearchTree.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Árvore Binária de Busca em C
* Kelvin Salton do Prado - 2015
*
* ( 6 )
* / \
Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions src/c/CalculatePi.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
Calculo de Pi em C
Bruno Dantas de Paiva - 2021
https://github.com/DantasB
*/

#include <stdio.h>
Expand Down
1 change: 0 additions & 1 deletion src/c/ListaCircularLigada.c → src/c/CircularLinkedList.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
*
* Lista Ligada com Nó Cabeça, Circular e Ordenada (Implementação Dinâmica)
* Kelvin Salton do Prado - 2015
*
*/

Expand Down
1 change: 0 additions & 1 deletion src/c/ComponentesConexos.c → src/c/ConnectedComponents.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
*
* Grafos - Algoritmo para calcular o número de componentes conexos em um determinado Grafo
* Kelvin Salton do Prado - 2015
*
* GRAFO
* (0) (1)-------------(4)---------------(5)
Expand Down
98 changes: 98 additions & 0 deletions src/c/DijkstraAlgorithm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Graphs - Dijkstra Algorithm in C
* Complexity: Theta(n^2)
*
* 1 for all - Edges with non-negative weights - Greedy algorithm
* Finds the shortest path from one vertex (start) to another (destination)
*
* Graph with 5 vertices and 6 edges
*
* 6
* (0)-----------------(1)
* | |
* 10 | | 2
* | 1 |
* (2)-----------------(3)
* \ /
* 3 \ / 8
* \ /
* -----(4)-----
*
* Distance Matrix
* 0 1 2 3 4
* 0 0 6 10 - -
* 1 6 0 - 2 -
* 2 10 - 0 1 3
* 3 - 2 1 0 8
* 4 - - 3 8 0
*
* For infinite values, the value will be considered: 4294967295
* The objective is to leave the starting point (0) and reach the destination (4) by the shortest route
* Response: (0)->(1)->(3)->(2)->(4) = 12
*
*/

#include <stdio.h>
#include <stdbool.h>

#define noVertices 5 // Defines a constant 5 which is the number of vertices in the graph

// Dijkstra's algorithm takes as parameters the distance matrix and the number of vertices
void Dijkstra(unsigned long int matrix[noVertices][noVertices], int n){

bool visited[n]; // Variable that holds true for visited vertices

// The value 'i' from the for below is not used, as the for is only used to traverse the entire number of columns in the matrix
for(int i = 1; i < n; i++){ // Starts at 1 because you don't need to compare the vertex with itself

int min = -1; // Variable that stores the position of the smallest value, starts at -1 as it is an invalid position
unsigned long int MinValue = 4294967295; // Variable that stores the smallest value found, starts with 'infinity', so always on the first pass the value will be smaller than this variable
// For that loops through all rows in column [0]
for(int j = 1; j < n; j++){
// If the vertex has not yet been visited and the value is less than the 'MinValor'
if( !visited[j] && matrix[j][0] < MinValue ){
min = j; // Saves the position of the smallest
MinValue = matrix[j][0]; // Save the smallest value
}
}

visited[min] = true; // Mark the value of the minimum position as visited

// Goes from 1 to n
for(int j = 1; j < n; j++){
// If the value of column [0] + the value of the passing column is less than the value of the passing row and column [0]
// Update the first column of the matrix, which will be used for the next iterations
if( (matrix[min][0] + matrix[min][j]) < matrix[j][0] ){
matrix[j][0] = matrix[min][0] + matrix[min][j];
}
}
}
}

int main(){

unsigned long int Matrix[noVertices][noVertices] = {{ 0, 6, 10, 4294967295, 4294967295 },
{ 6, 0, 4294967295, 2, 4294967295 },
{ 10, 4294967295, 0, 1, 3 },
{ 4294967295, 2, 1, 0, 8 },
{ 4294967295, 4294967295, 3, 8, 0 }};

Dijkstra(Matrix, noVertices);

printf("Total shortest path from vertex 0 to 4: %lu\n", Matrix[4][0]); // Shortest total path

// Print the matrix with the updated values
printf("Matrix:\n");
for (int i = 0; i < noVertices; ++i){
for (int e = 0; e < noVertices; ++e){
if( Matrix[i][e] < 10 )
printf(" %lu ", Matrix[i][e]);
else
printf("%lu ", Matrix[i][e]);
}
printf("\n");
}
printf("\n");

return 0;
}
13 changes: 6 additions & 7 deletions src/c/ListaDuplamenteEncadeada.c → src/c/DoublyLinkedList.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/*
* Exemplo Lista Duplamente Encadeada em C
* Luan Felipe dos S. da Silva
*/


#include <stdio.h>
#include <stdlib.h>

/* Lista encadeada utilizando celula cabeça */
/* Lista encadeada utilizando celula cabeça */

typedef struct cel celula;
struct cel{
Expand All @@ -16,15 +15,15 @@ struct cel{
struct cel *ant;
};

/* O ponteiro 'p' é a cabeça da lista*/
/* O ponteiro 'p' é a cabeça da lista*/

void insereInicio(int x, celula *p) /* Insere no inicio da lista*/
{
celula *nova, *q;
nova = malloc (sizeof (celula));
nova->dado = x;
nova->prox = p->prox;
/* verifica se a lista está vazia*/
/* verifica se a lista está vazia*/
if (p->prox != NULL)
{
q = nova->prox;
Expand Down Expand Up @@ -93,9 +92,9 @@ void libera (celula *ini)
celula *p;
p=ini;
while (p != NULL) {
celula *q = p->prox; /* guarda referência para o próximo elemento*/
free(p); /* libera a memória apontada por p */
p = q; /* faz p apontar para o próximo */
celula *q = p->prox; /* guarda referência para o próximo elemento*/
free(p); /* libera a memória apontada por p */
p = q; /* faz p apontar para o próximo */
}
}

Expand Down
1 change: 0 additions & 1 deletion src/c/FilaEncadeadaDinamica.c → src/c/DynamicQueue.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Implementação de uma Estrutura de Fila Dinâmica Ligada/Encadeada em C
* Kelvin Salton do Prado - 2015
*/

#include <stdio.h>
Expand Down
1 change: 0 additions & 1 deletion src/c/PilhaLigadaDinamica.c → src/c/DynamicStack.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Pilha Dinâmica utilizando uma Lista Ligada em C
* Kelvin Salton do Prado - 2015
*/

#include <stdio.h>
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion src/c/Fatorial.c → src/c/Factorial.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/*
* Exemplos de função para retornar o fatorial de um número n
* função recursiva
* Jhonata Ribeiro - 2017
*/

int main(){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Grafos - Algoritmo de Floyd-Warshall em C
* Kelvin Salton do Prado - 2015
* Complexidade: Teta de vértices ao cubo = Teta(n^3)
*
* Encontra o caminho de todos para todos os vértices
Expand Down
1 change: 0 additions & 1 deletion src/c/BuscaEmGrafo.c → src/c/GraphSearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
*
* Grafos - Implementação de uma estrutura de Grafo não dirigido em C
* Métodos de Busca: Busca em Profundidade e Busca em Largura
* Kelvin Salton do Prado - 2015
*
*
* (A)---------------(B)-------------(E)---------------(F)
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion src/c/CicloHamiltoniano.c → src/c/HamiltonianCycle.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
*
* Grafos - CICLO HAMILTONIANO em C
* Kelvin Salton do Prado - 2015
*
* -----------------------------------
* | |
Expand Down
2 changes: 0 additions & 2 deletions src/c/InsertionSort.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
Algoritmo de ordenação Insertion Sort em C
Vinicios Barbosa da Silva - 2023
https://github.com/ViniciosB
*/

#include <stdio.h> // Necessário para usar input e output
Expand Down
File renamed without changes.
Loading

0 comments on commit 8e90dbb

Please sign in to comment.