Skip to content

Instantly share code, notes, and snippets.

View benapie's full-sized avatar

Ben Napier benapie

View GitHub Profile
@benapie
benapie / prims_algorithm.cpp
Last active March 13, 2019 19:37
Prim's algorithm using cgraph.
//
// Created by Ben Napier on 08/03/2019.
//
#include <iostream>
#include "Graph.h"
int main() {
// Lets implement a bit of Prim's...
// First set up our graph.
Graph graph;
@benapie
benapie / dependencies.tex
Last active February 12, 2019 21:08
Master list of dependencies for LaTeX files.
% Typical maths
\usepackage{amssymb} % Cool symbols like \mathbb{R}
\usepackage{bm} % Bold symbols, \bm{v}
\usepackage{mathtools} % Main maths package, imports amsmath
\usepackage{enumitem} % allows next line
\setlist[enumerate,1]{label={(\roman*)}} % changing default numbering scheme
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert} % absolute operator
% Probability
\usepackage{mathtools}
@benapie
benapie / bucket_sort.cpp
Created January 19, 2019 01:33
Bucket sort implementation in C++.
void bucket_sort(int data_array[], int array_size) {
// First we find the maximum value in the list so we know how much space to allocate.
int maximum_value = 0;
for (int i = 0; i < array_size; ++i) {
if (data_array[i] > maximum_value) {
maximum_value = data_array[i];
}
}
auto bucket_vector = std::vector<unsigned >(static_cast<unsigned int>(maximum_value + 1));
// And now we fill our buckets.
@benapie
benapie / queue_with_array.cpp
Last active January 12, 2019 11:36
Implementation of a queue data type using arrays in C++.
#define MAX_SIZE 32
/**
* Implementation of a queue data type using an array.
*/
class QueueWithArray {
private:
int data_array[MAX_SIZE] = {};
int size = 0;
int front_index = 0;
@benapie
benapie / stack_with_array.cpp
Last active January 12, 2019 11:31
Implementation of a stack data type using arrays in C++.
#define MAX_SIZE 32
/**
* Implementation of a stack data type using an array.
*/
class Stack {
private:
int data_array[MAX_SIZE] = {};
int size = 0;
public:
@benapie
benapie / circularly_linked_list.cpp
Last active January 6, 2019 21:16
Simple circularly linked list implementation in C++ with insert and delete functions.
/**
* Simple node data structure for a circularly linked list.
*/
class Node {
public:
Node *next = nullptr;
int data;
};
/**
@benapie
benapie / doubly_linked_list.cpp
Last active January 6, 2019 20:44
Simple doubly linked list implementation in C++ with find, delete, and insert functions.
/**
* Simple node data structure for a doubly linked list.
*/
class Node {
public:
Node *next = nullptr;
Node *prev = nullptr;
int data;
};
@benapie
benapie / singly_linked_list.cpp
Last active May 4, 2021 20:24
Simple singly linked list implementation in C++ with find, delete, and insert functions.
/**
* Simple node data structure for a singly linked list.
*/
class Node {
public:
Node *next = nullptr;
int data;
};
/**
@benapie
benapie / var_proportion_plot.R
Last active February 7, 2018 12:01
This is a plot for analysing the relationship between a proportion and a variable. Calculates the proportion for sets with a lower limit of a specific variable and calculates the proportions as you move the lower limit up. Even includes a count bar so you know how much data is there, graph starts at the 1st percentile and ends when the number of…
table <- tibble(Measure = numeric(), Percent = numeric(), Count = numeric())
for (i in seq(main$Measure %>% quantile(0.01) %>% round(1), max(main$Measure), 0.1)) {
main.sub <- main %>% filter(Measure > i)
prop.count <- main.sub$IsCondition %>% which() %>% length()
count <- main.sub %>% nrow()
if (prop.count < 30) {
break
}
table <- table %>% add_row(Measure = i,
Percent = 100 * prop.count / count,
@benapie
benapie / point_plot.R
Created January 30, 2018 10:53
Basic plot of two variables as a scatter plot.
ggplot(data)+
geom_point(aes(Value.X, Value.Y), shape = 0)