Skip to content

Instantly share code, notes, and snippets.

View misterpoloy's full-sized avatar
πŸ‘½
Software Engineer

Juan P. Ortiz misterpoloy

πŸ‘½
Software Engineer
View GitHub Profile
@misterpoloy
misterpoloy / ReverseLinkedListStack.cpp
Created January 14, 2020 19:27
Reverse a Linked List using Stack
#include <iostream>
#include <stack>
struct Node {
int value;
Node* next;
Node(int value)
:next(nullptr), value(value)
{
@misterpoloy
misterpoloy / StackStringReverse.cpp
Created January 14, 2020 19:44
String Reverse using Stack with c++
#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
@misterpoloy
misterpoloy / ParseInfixToPosfix.cpp
Created January 16, 2020 21:11
Infix to posfix using stack
#include <iostream>
#include <string>
#include <stack>
bool isOperator(char x) {
if (x == '+' || x == '-' || x == '*' || x == '/')
return true;
return false;
}
@misterpoloy
misterpoloy / QueueInt.cpp
Created January 16, 2020 22:36
Queue Integer Implementation
// 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;
@misterpoloy
misterpoloy / QueueLinkedList.cpp
Created January 16, 2020 23:19
Queue Implementation using a linked list
// 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)
{
@misterpoloy
misterpoloy / SquareRoot.cpp
Created January 21, 2020 00:01
Get square root using Newtons formula = The equation 𝑛𝑒𝑀𝑔𝑒𝑒𝑠𝑠=12βˆ—(π‘œπ‘™π‘‘π‘”π‘’π‘’π‘ π‘ +π‘›π‘œπ‘™π‘‘π‘”π‘’π‘’π‘ π‘ )
#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));
}
@misterpoloy
misterpoloy / InfiniteMoneky.cpp
Created January 22, 2020 19:02
infinite monkey theorem
// 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) {
@misterpoloy
misterpoloy / BinaryTree.cpp
Last active June 7, 2020 03:06
Binary tree example implementation in cpp, including mirrow function
#include <iostream>
#include <queue>
#include <climits>
struct BSTNode {
int value;
BSTNode* left;
BSTNode* right;
BSTNode() {
left = right = nullptr;
@misterpoloy
misterpoloy / index.js
Created February 19, 2020 03:11
Twitter Code Interview
const CHUNKS = 3;
/** @paran {array} input */
function mostFrecuentHistory(input) {
const globalCounter = {}
input.forEach(arr => {
arr.forEach(log => {
if (!globalCounter[log]) {
globalCounter[log] = 0;
@misterpoloy
misterpoloy / SelectionSort.cpp
Created April 9, 2020 21:53
Selection Sort in cpp
#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
}
}