Skip to content

Instantly share code, notes, and snippets.

View maxgoren's full-sized avatar

Max Goren maxgoren

View GitHub Profile
struct Point {
int x;
int y;
char s;
bool blocks;
color_t color;
bool operator==(const Point& other) const {
return x == other.x && y == other.y;
}
bool operator!=(const Point& other) const {
@maxgoren
maxgoren / breadthfirst_WORKS.h
Last active July 21, 2020 03:11
After fixing a myriad of bugs, it works. now time for optimization.
struct Point {
int x;
int y;
char s;
bool blocks;
color_t color;
bool operator==(const Point& other) const {
return x == other.x && y == other.y;
}
@maxgoren
maxgoren / cave_gen.h
Last active September 8, 2020 07:31
Cave Generator using Cellular Automata.
//How it works: automaton()->prep_fields()->place_seeds()->four_five()->flood_fill()->automaton() -> done.
// v ^
// count_neighbors()
//How its used: Cave myCave(160, 40);
// myCave.automaton();
//
//The completed cave is then available as myCave.layout;
#include <array>
#include <vector>
#include <list>
template <typename T>
void shellSort(vector<T>& arr)
{
int N = arr.size();
for (int gap = N/2; gap > 0; gap /= 2)
{
for (int i = gap; i < N; i += 1)
{
int temp = arr[i];
int j;
#include <iostream>
using namespace std;
struct Student {
std::string name;
int age;
int grade_level;
double gpa;
};
@maxgoren
maxgoren / retvals.c
Created October 22, 2021 18:22
using a struct to return multiple values of different types in c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct retVals {
double result;
char *str;
};
struct retVals* baz(int foo, int bar)
#include <iostream>
using namespace std;
std::pair<double, string> baz(int foo, int bar)
{
double ans = double(foo)/double(bar);
return std::make_pair(ans, "Just Because.");
}
int main()
std::tuple<double, string, float, float> baz(int foo, int bar)
{
double ans = double(foo)/double(bar);
return std::make_tuple(ans, "Just Because.", float(foo), float(bar));
}
int main()
{
auto [answer, reply, foo, bar] = baz(8, 3);
std::cout<<foo<<"/"<<bar<<" = ";
@maxgoren
maxgoren / deletemin.java
Created February 18, 2022 19:12
deletemin
private Node<K,V> getMin(Node<K,V> h)
{
if (h.leftChild() == null)
return h;
return getMin(h.leftChild());
}
private Node<K,V> deleteMin(Node<K,V> h)
{
if (h.leftChild() == null)
@maxgoren
maxgoren / deleteNode.java
Created February 18, 2022 19:14
delete arbitrary nodes
private Node<K,V> delete(Node<K,V> h, K key)
{
if (h == null)
return null;
if (key.compareTo(h.key()) < 0)
h.setLeft(delete(h.leftChild(), key));
else if (key.compareTo(h.key()) > 0)
h.setRight(delete(h.rightChild(), key));
else {