-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'kelvins:main' into countingSort/in-js
- Loading branch information
Showing
94 changed files
with
2,119 additions
and
988 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) | ||
* / \ | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/c/AlgoritmoFloydWarshall.c → src/c/FloydWarshallAlgorithm.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.