Skip to content
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Com o objetivo de alcançar uma abrangência maior e encorajar novas pessoas a c
| [Algoritmo Floyd Warshall][2] | [C](./src/c/AlgoritmoFloydWarshall.c) | C++ | Java | [Python](./src/python/floyd_warshall.py) | Go | Ruby | JS | Pascal | Swift | Rust |
| [Busca Binária][5] | C | [C++](./src/cpp/BinarySearch.cpp) | Java | [Python](./src/python/busca_binaria.py) | [Go](./src/go/busca_binaria/busca_binaria.go) | [Ruby](./src/ruby/BuscaBinaria.rb) | [JS](./src/javascript/BinarySearch.js) | [Pascal](./src/pascal/busca-binaria.pas) | Swift | Rust |
| [Busca em Grafos][6] | [C](./src/c/BuscaEmGrafo.c) | C++ | Java | [Python](./src/python/busca_em_grafo.py) | Go | Ruby | [JS](./src/javascript/GraphSearch.js) | Pascal | Swift | Rust |
| [Busca Sequencial][7] | [C](./src/c/BuscaSequencial.c) | C++ | Java | [Python](./src/python/busca_sequencial.py) | Go | [Ruby](./src/ruby/BuscaSequencial.rb) | [JS](./src/javascript/BuscaLinear.js) | Pascal | Swift | Rust |
| [Busca Sequencial][7] | [C](./src/c/BuscaSequencial.c) | [C++](./src/cpp/BuscaSequencial.cpp) | Java | [Python](./src/python/busca_sequencial.py) | Go | [Ruby](./src/ruby/BuscaSequencial.rb) | [JS](./src/javascript/BuscaLinear.js) | Pascal | Swift | Rust |
| [Busca Sequencial Recursiva][8] | [C](./src/c/BuscaSequencialRecursiva.c) | C++ | Java | [Python](./src/python/busca_sequencial_recursiva.py) | Go | [Ruby](src/ruby/Busca_Sequencial_Recursiva.rb) | [JS](./src/javascript/RecursiveLinearSearch.js) | Pascal | Swift | Rust |
| [Busca utilizando Sentinela][9] | [C](./src/c/BuscaSentinela.c) | C++ | Java | [Python](./src/python/busca_sentinela.py) | Go | [Ruby](./src/ruby/BuscaSentinela.rb) | [JS](./src/javascript/busca_sentinela.js) | Pascal | Swift | Rust |
| [Busca por Interpolação][55] | C | [C++](./src/cpp/Interpolation_search.cpp) | Java | [Python](./src/python/interpolation_search.py) | Go | Ruby | JS | Pascal | Swift | Rust |
Expand All @@ -22,8 +22,8 @@ Com o objetivo de alcançar uma abrangência maior e encorajar novas pessoas a c
| [Fatorial][15] | [C](./src/c/Fatorial.c) | [C++](./src/cpp/Fatorial.cpp) | [Java](./src/java/Fatorial.java) | [Python](./src/python/fatorial.py) | [Go](./src/go/fatorial/fatorial.go) | [Ruby](./src/ruby/Fatorial.rb) | [JS](./src/javascript/Factorial.js) | [Pascal](./src/pascal/fatorial.pas) | [Swift](./src/swift/fatorial.swift) | Rust |
| [Fatorial Recursiva][16] | [C](./src/c/FatorialRecursiva.c) | [C++](./src/cpp/FatorialRecursiva.cpp) | [Java](./src/java/FatorialRecursiva.java) | [Python](./src/python/fatorial_recursiva.py) | Go | [Ruby](./src/ruby/Fatorial.rb) | [JS](./src/javascript/FactorialRecursive.js) | [Pascal](src/pascal/fatorial-recusiva.pas) | [Swift](./src/swift/fatorialRecursivo.swift) | [Rust](./src/rust/fatorial_recursiva.rs) |
| [Fibonacci][17] | C | [C++](./src/cpp/Fibonacci.cpp) | [Java](./src/java/Fibonacci.java) | [Python](./src/python/fibonacci.py) | [Go](./src/go/fibonacci/fibonacci.go) | [Ruby](./src/ruby/Fibonacci.rb) | [JS](./src/javascript/Fibonacci.js) | Pascal | [Swift](./src/swift/fibonacci.swift) | [Rust](./src/rust/fibonacci.rs) |
| [Máximo Recursivo][26] | [C](./src/c/MaxRecursivo.c) | C++ | Java | [Python](./src/python/maximo_recursivo.py) | Go | Ruby | [JS](./src/javascript/MaxRecursive.js) | Pascal | Swift | Rust |
| [Mín. e Máx. Iterativo][27] | C | C++ | [Java](./src/java/MaxMinArray.java) | [Python](./src/python/min_max_iterativo.py) | Go | Ruby | [JS](./src/javascript/IterativeMinAndMax.js) | Pascal | Swift | [Rust](./src/rust/min_max_iterativo.rs) |
| [Máximo Recursivo][26] | [C](./src/c/MaxRecursivo.c) | [C++](./src/cpp/MaximoRecursivo.cpp) | Java | [Python](./src/python/maximo_recursivo.py) | Go | Ruby | [JS](./src/javascript/MaxRecursive.js) | Pascal | Swift | Rust |
| [Mín. e Máx. Iterativo][27] | C | [C++](./src/cpp/MinMaxIterativo.cpp) | [Java](./src/java/MaxMinArray.java) | [Python](./src/python/min_max_iterativo.py) | Go | Ruby | [JS](./src/javascript/IterativeMinAndMax.js) | Pascal | Swift | [Rust](./src/rust/min_max_iterativo.rs) |
| [Mín. e Máx. Recursivo][28] | [C](./src/c/MaxMinRecursivo.c) | C++ | Java | [Python](./src/python/maximo_minimo_recursivo.py) | [Go](./src/go/maximominimo/MaximoMinimo.go) | Ruby | [JS](./src/javascript/RecursiveMinAndMax.js) | Pascal | Swift | [Rust](./src/rust/min_max_recursivo.rs) |
| Mín. e Máx. D&C | C | C++ | Java | [Python](./src/python/maximo_minimo_dc.py) | [Go](./src/go/maximominimo/MaximoMinimo.go) | Ruby | JS | Pascal | Swift | Rust |
| [Passeio do Cavalo][30] | C | C++ | Java | [Python](./src/python/passeio_do_cavalo.py) | Go | Ruby | JS | Pascal | Swift | Rust |
Expand Down Expand Up @@ -55,7 +55,7 @@ Com o objetivo de alcançar uma abrangência maior e encorajar novas pessoas a c
| [Bucket Sort][36] | C | C++ | [Java](./src/java/BucketSort.java) | Python | Go | [Ruby](./src/ruby/bucket_sort.rb) | JS | Pascal | Swift | Rust |
| [Cocktail Sort][37] | C | C++ | Java | Python | [Go](./src/go/cocktailsort/cocktailsort.go) | Ruby | JS | Pascal | Swift | Rust |
| [Comb Sort][38] | C | C++ | Java | Python | [Go](./src/go/combsort/combsort.go) | Ruby | [JS](./src/javascript/CombSort.js) | Pascal | Swift | Rust |
| [Counting Sort][39] | C | C++ | Java | Python | [Go](./src/go/countingsort/countingsort.go) | [Ruby](./src/ruby/count_sort.rb) | JS | Pascal | Swift | Rust |
| [Counting Sort][39] | C | [C++](./src/cpp/CountingSort.cpp) | Java | Python | [Go](./src/go/countingsort/countingsort.go) | [Ruby](./src/ruby/count_sort.rb) | JS | Pascal | Swift | Rust |
| [Gnome Sort][40] | C | C++ | Java | Python | [Go](./src/go/gnomesort/gnomesort.go) | Ruby | JS | Pascal | Swift | [Rust](./src/rust/gnomesort.rs) |
| [Heapsort][41] | C | C++ | [Java](./src/java/HeapSort.java) | Python | [Go](./src/go/heapsort/heapsort.go) | [Ruby](./src/ruby/heap_sort.rb) | [JS](./src/javascript/HeapSort.js) | [Pascal](./src/pascal/heapsort.pas) | Swift | Rust |
| [Insertion Sort][42] | C | [C++](./src/cpp/InsertionSort.cpp) | [Java](./src/java/InsertionSort.java) | [Python](./src/python/insertion_sort.py) | [Go](./src/go/insertionsort/insertionsort.go) | [Ruby](./src/ruby/insertion_sort.rb) | [JS](./src/javascript/InsertionSort.js) | Pascal | [Swift](./src/swift/insertionSort.swift) | [Rust](./src/rust/insertion_sort.rs) |
Expand Down
36 changes: 36 additions & 0 deletions src/cpp/BuscaSequencial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>
#include <vector>

using namespace std;

int busca_sequencial(vector<int> &nums, int target) {

for (size_t i = 0; i < nums.size(); i++) {

if(nums[i] == target)
return i;
}

return -1;
}

int main() {

vector<int> nums = {1, 2, 3, 4, 5, 27, -1, 12, 999};
int target;

cout << "Digite o numero que deseja busca no vetor: ";
cin >> target;
cout << "\n";

int pos = busca_sequencial(nums, target);

if(pos > -1) {
cout << "Numero encontrado no vetor na posicao: " << pos << endl;
}
else {
cout << "Numero nao encontrado no vetor." << endl;
}

return 0;
}
107 changes: 107 additions & 0 deletions src/cpp/CountingSort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> counting_sort(vector<int>& nums) {


// nums = {5, 0, 1, 2, 3, 5, 3, 0, 9, 4}
// max = 9
// vector nums contem elementos entre [0 .. max]
auto max = *max_element(nums.begin(), nums.end());


// cria um vector com max + 1 posicoes para contar ocorrências de cada elemento
// 0 1 2 3 4 5 6 7 8 9 -> elementos possiveis de ocorrer no vector nums
//counting = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
vector<int> counting(max+1);


// conta ocorrencias de cada elemento
// nums = {5, 0, 1, 2, 3, 5, 3, 0, 9, 4}
//
// 0 1 2 3 4 5 6 7 8 9
// counting = {2, 1, 1, 2, 1, 2, 0, 0, 0, 1}
//
for(auto& i : nums) {
counting[i]++;
}


// agora, counting = {2, 3, 4, 6, 7, 9, 9, 9, 9, 10}
// sera utilizado para determinar as posicoes dos elementos no vector ordenado
for (size_t i = 1; i < counting.size(); i++) {

counting[i] += counting[i-1];
}

vector<int> sorted(nums.size());

/*

O proximo loop coloca os numeros em suas devidas posicoes no vetor ordenado
i = itera pelos elementos de nums
counting[i] -1 é a posicao que o elemento i devee assumir no vetor ordenado

Os 3 primeiros passos seriam:

nums = {5, 0, 1, 2, 3, 5, 3, 0, 9, 4}
counting = {2, 3, 4, 6, 7, 9, 9, 9, 9, 10}
sorted = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

passo 1:
i = 5
counting[i] => counting[5] => 9
sorted[9 - 1] => sorted[8] = i => sorted[8] = 5
sorted = {0, 0, 0, 0, 0, 0, 0, 0, 5, 0}

passo 2:
i = 0
counting[i] => counting[0] => 2
sorted[2 - 1] => sorted[1] = i => sorted[1] = 0
sorted = {0, 0, 0, 0, 0, 0, 0, 0, 5, 0}

passo 3:
i = 1
counting[i] => counting[1] => 3
sorted[3 - 1] => sorted[2] = i => sorted[2] = 1
sorted = {0, 0, 1, 0, 0, 0, 0, 0, 5, 0}
*/
for(auto& i : nums) {
sorted[ counting[i]-1 ] = i;
counting[i]--;
}

return sorted;
}

void print_vector(vector<int> vec) {

cout << "[";
for (size_t i = 0; i < vec.size(); i++) {
if(i != vec.size()-1) {
cout << vec[i] << ", ";
}
else {
cout << vec[i];
}
}
cout << "]" << endl;
}

int main() {

vector<int> nums{5, 0, 1, 2, 3, 5, 3, 0, 9, 4};

vector<int> sorted = counting_sort(nums);

cout << "Original vector = ";
print_vector(nums);

cout << "Sorted vector = ";
print_vector(sorted);

return 0;
}
83 changes: 83 additions & 0 deletions src/cpp/ListaEncadeada.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <iostream>

using namespace std;

struct Node{

int val;
Node* next;

Node(int val) : val(val), next(nullptr) {}
Node(int val, Node *next) : val(val), next(next) {}
};

void print_list(Node *head) {

auto aux = head;
while(aux) {

cout << aux->val;

if(aux->next) {
cout << " -> ";
}

aux = aux->next;
}
cout << endl;
}

void push_back(Node **head, int val) {


Node *newNode = new Node(val);

if(*head == nullptr) {
*head = newNode;
}

else {

auto aux = *head;

while(aux->next) {
aux = aux->next;
}

aux->next = newNode;
}
}

void push_front(Node **head, int val) {


Node *newNode = new Node(val);

if(*head == nullptr) {
*head = newNode;
}

else {

auto aux = *head;

while(aux->next) {
aux = aux->next;
}

aux->next = newNode;
}
}

int main() {

Node *head = nullptr;


push_back(&head, 1);
push_back(&head, 2);
push_back(&head, 3);
push_back(&head, 4);
push_back(&head, 5);
print_list(head);
}
37 changes: 37 additions & 0 deletions src/cpp/MaximoRecursivo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <iostream>
#include <vector>


int max_recursivo(std::vector<int> nums, int n) {

if(n == 1)
return nums[0];
else{
int aux = max_recursivo(nums, n-1);

if(aux > nums[n-1])
return aux;

return nums[n-1];
}
}

int main() {

std::vector<int> nums{1, 2, 3, 4, 32, 6, 7, 8, 9, 10};

std::cout << "nums = {";
for(auto& i : nums) {

std::cout << i;

if(&i != &nums.back()) {
std::cout << ",";
}
}
std::cout << "}" << std::endl;

std::cout << "Max = " << max_recursivo(nums, nums.size()) << std::endl;

return 0;
}
20 changes: 20 additions & 0 deletions src/cpp/MinMaxIterativo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>

using namespace std;

int main() {

int arr[] = {1, 5, -20, 6, 15};

int min = arr[0];
int max = arr[0];

for(auto& i : arr) {
if(i < min) min = i;
else if(i > max) max = i;
}

cout << "Max = " + to_string(max) + "\nMin = " + to_string(min) << endl;

return 0;
}