Skip to content

Instantly share code, notes, and snippets.

View maxgoren's full-sized avatar

Max Goren maxgoren

View GitHub Profile
@maxgoren
maxgoren / bfs.hpp
Created May 18, 2024 02:55
NFA using digraph
#ifndef bfs_hpp
#define bfs_hpp
#include "digraph.hpp"
#include "queue.hpp"
class BFS {
private:
bool *seen;
int *pred;
void init(Digraph& G) {
@maxgoren
maxgoren / bag.hpp
Created May 17, 2024 03:00
Some helpful ADT's for working with directed graphs
#ifndef bag_hpp
#define bag_hpp
template <class T>
class BagIter {
private:
T* curr;
public:
BagIter(T* pos) {
curr = pos;
@maxgoren
maxgoren / sort_single_linked_list.cpp
Created April 29, 2024 21:08
singly linked list sort routines (selection sort, insertion sort, merge sort)
#include <iostream>
using namespace std;
struct node {
int info;
node* next;
node(int i = 0, node* n = nullptr) : info(i), next(n) { }
};
@maxgoren
maxgoren / deque.hpp
Last active April 28, 2024 21:48
a simplified version of std::deque
#ifndef simple_deque_hpp
#define simple_deque_hpp
template <class T>
class simple_deque_iterator;
template <class T>
class simple_deque {
private:
using iterator = simple_deque_iterator<T>;
@maxgoren
maxgoren / bplus.cpp
Created January 10, 2024 05:30
dead simple b plus tree insertion
const int M = 4;
template <class K, class V>
struct node;
template <class K, class V>
struct entry {
K key;
V value;
node<K,V>* next;
@maxgoren
maxgoren / marksweep_bst.c
Last active December 26, 2023 02:36
Mark/Sweep GC example with BST in C
/*
Example of how mark/sweep garbage collection works.
MIT License
Copyright (c) 2023 Max Goren - http://www.maxgcoding.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@maxgoren
maxgoren / heapsort.cpp
Last active November 19, 2023 22:21
showing the difference between williams and floyds heapsort implementations.
#include <iostream>
using namespace std;
template <class T>
void print(T a[], int n) {
for (int i = 0; i < n; i++) {
cout<<a[i]<<" ";
}
cout<<endl;
}
@maxgoren
maxgoren / tree-viz.cpp
Created October 25, 2023 18:50
AVL, RB, LLRB tree's, and a OpenGL based Tree visualizer.
#include <vector>
#include <limits>
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace std;
template <class K, class V>
struct rbnode {
K key;
V value;
@maxgoren
maxgoren / evalinfix.cpp
Last active October 17, 2023 02:17
evaluate infix expressions, shunting yard approach,.
class Evaluate {
private:
template <class T>
struct Stack : public stack<T> {
T pop() {
T ret = stack<T>::top();
stack<T>::pop();
//cout<<"Pop: "<<ret<<endl;
return ret;
}
@maxgoren
maxgoren / skiplistinsert.java
Created August 12, 2023 21:30
canonical skiplist insertion
import java.util.Random;
public class SkipList {
private static final int MAX_LEVEL = 7;
private Random rng;
private class Node {
public Character info;
public int level;
public Node[] forward;
Node(char i, int level) {