This file contains hidden or 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
#include <iostream> | |
#include <stack> | |
struct Node { | |
int value; | |
Node* next; | |
Node(int value) | |
:next(nullptr), value(value) | |
{ |
This file contains hidden or 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
#include <iostream> | |
#include <stack> | |
char* reverse(char* str, int size) { | |
std::stack<char> myText; | |
// Don't count the null character array | |
for (int i = 0; i < size - 1; i++) { | |
myText.push(str[i]); | |
} | |
// Don't count the null character array |
This file contains hidden or 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
#include <iostream> | |
#include <string> | |
#include <stack> | |
bool isOperator(char x) { | |
if (x == '+' || x == '-' || x == '*' || x == '/') | |
return true; | |
return false; | |
} |
This file contains hidden or 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
// TODO, I can use templates to make it more generic? | |
// https://www.youtube.com/watch?v=okr-XE8yTO8&list=PL2_aWCzGMAwI3W_JlcBbtYTwiQSsOTa6P&index=23 | |
#include <iostream> | |
#define MAX_SIZE 5 | |
class Queue { | |
private: | |
int Data[MAX_SIZE]; | |
int head, rear; |
This file contains hidden or 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
// https://www.youtube.com/watch?v=A5_XdiK4J8A&list=PL2_aWCzGMAwI3W_JlcBbtYTwiQSsOTa6P&index=24 | |
#include <iostream> | |
struct Node { | |
int value; | |
Node* next; | |
Node(int x) | |
: next(nullptr), value(x) | |
{ |
This file contains hidden or 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
#include <iostream> | |
using namespace std; | |
double squareroot(double n) { /*return type int which indicates | |
that a decimal is being returned*/ | |
double root = n / 2; | |
for (int i = 0; i < 20; i++) { | |
root = (.5) * (root + (n / root)); | |
} |
This file contains hidden or 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
// https://runestone.academy/runestone/books/published/cppds/Introduction/DefiningFunctions.html | |
#include <iostream> | |
#include <random> | |
#include <string> | |
#include <chrono> | |
std::mt19937 rng; | |
std::string gerateRandomString(int length) { |
This file contains hidden or 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
#include <iostream> | |
#include <queue> | |
#include <climits> | |
struct BSTNode { | |
int value; | |
BSTNode* left; | |
BSTNode* right; | |
BSTNode() { | |
left = right = nullptr; |
This file contains hidden or 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
const CHUNKS = 3; | |
/** @paran {array} input */ | |
function mostFrecuentHistory(input) { | |
const globalCounter = {} | |
input.forEach(arr => { | |
arr.forEach(log => { | |
if (!globalCounter[log]) { | |
globalCounter[log] = 0; |
This file contains hidden or 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
#include <iostream> | |
void selectionSort(int* myList, int length) { | |
for (int i = 0; i < length - 1; i++) { // Actually is ok only n -2 | |
int indexMin = i; // ith position: elements from i till n-1 are candidates | |
for (int j = i + 1; j < length; j++) { // Analizo el siguiente | |
if (myList[j] < myList[indexMin]) { | |
indexMin = j; // update the index of minimun element | |
} | |
} |