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 / DoubleLinkedList.cpp
Created January 10, 2020 23:35
(Naiv) Double linked list
// xhttps://www.youtube.com/watch?v=VOQNf1VxU3Q&list=PL2_aWCzGMAwI3W_JlcBbtYTwiQSsOTa6P&index=14&t=0s
#include <iostream>
struct Node {
int value;
Node* prev;
Node* next;
Node(int x): prev(nullptr), next(nullptr)
{
@misterpoloy
misterpoloy / FactorsOfANumber.cpp
Created January 10, 2020 23:39
Find all factors of a number using c++
// https://www.youtube.com/watch?v=dolcMgiJ7I0&list=PL2_aWCzGMAwLL-mEB4ef20f3iqWMGWa25&index=6&t=0s
#include <iostream>
#include <list>
#include <cmath>
// Big O(sqrt(n))
std::list<int> getFactors(int n) {
std::list<int> factors;
for (int i = 1; i <= sqrt(n); i++) {
@misterpoloy
misterpoloy / FindingPrimeNumbers.cpp
Created January 10, 2020 23:46
Finding Prime Numbers (division and Sieve of Eratosthenes)
// https://www.youtube.com/watch?v=eKp56OLhoQs&list=PL2_aWCzGMAwLL-mEB4ef20f3iqWMGWa25&index=5&t=0s
#include <iostream>
#include <list>
#include <cmath>
// Trial Division = O(sqrt(n))
bool isPrime(int n) {
bool result = true;
// Use square root optimization
@misterpoloy
misterpoloy / FunctionPointerCallback.cpp
Last active January 10, 2020 23:53
Pointer function using callback
// https://www.youtube.com/watch?v=LW8Rfh6TzGg&list=PL2_aWCzGMAwLZp6LMUKI3cc7pgGsasm2_&index=5
#include <iostream>
void helloWorld() {
std::cout << "Hello world" << std::endl;
};
void myFunction(void (*callback)()) {
callback();
@misterpoloy
misterpoloy / FunctionPointer.cpp
Created January 10, 2020 23:54
Function Pointer
// https://www.youtube.com/watch?v=LW8Rfh6TzGg&list=PL2_aWCzGMAwLZp6LMUKI3cc7pgGsasm2_&index=5
#include <iostream>
int add(int a, int b) {
return a + b;
}
int main() {
@misterpoloy
misterpoloy / LinkedList.cpp
Last active October 6, 2021 23:48
Linked List
// https://www.youtube.com/watch?v=vcQIFT79_50&list=PL2_aWCzGMAwI3W_JlcBbtYTwiQSsOTa6P&index=6&t=0s
#include <iostream>
struct Node {
int value;
Node* next;
};
class LinkedList {
@misterpoloy
misterpoloy / GCD.cpp
Created January 11, 2020 00:04
MCD Maximo comun denominador (GCD) euclides
// https://www.youtube.com/watch?v=7HCd074v8g8&list=PL2_aWCzGMAwLL-mEB4ef20f3iqWMGWa25&index=8&t=0s
#include <iostream>
#include <list>
#include <cmath>
int brutDivision(int a, int b) {
int gcd = 1;
std::list<int> factors;
for (int i = 2; i < sqrt(a); i++) {
@misterpoloy
misterpoloy / StringClass.cpp
Created January 11, 2020 00:11
Naiv String Class
// https://www.youtube.com/watch?v=ijIxcB9qjaU&list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb&index=32
#include <iostream>
class String {
private:
char* m_Buffer;
unsigned int m_Size;
public:
String(const char* string) {
@misterpoloy
misterpoloy / PrimeFactors.cpp
Created January 11, 2020 00:25
Prime factorization of a number
// https://www.youtube.com/watch?v=6PDtgHhpCHo&list=PL2_aWCzGMAwLL-mEB4ef20f3iqWMGWa25&index=7&t=0s
#include <iostream>
#include <list>
#include <cmath>
std::list<int> getPrimeFactors(int n) {
std::list<int> factors;
int times = n;
// Optimization to BIG O(sqrt(n))
@misterpoloy
misterpoloy / PostFixEvaluation.cpp
Created January 14, 2020 19:15
Evaluate Postfix Expression using Stack
#include <iostream>
#include <string>
#include <stack>
bool isOperator(char x) {
if (x == '+' || x == '-' || x == '*' || x == '/' )
return true;
return false;
}