Skip to content

Instantly share code, notes, and snippets.

@dgodfrey206
dgodfrey206 / mergeSortLL.cpp
Last active June 14, 2022 21:21
Linked list merge sort
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include<bits/stdc++.h>
using namespace std;
struct ListNode {
int val;
ListNode* next = nullptr;
ListNode(int data):val(data){}
@dgodfrey206
dgodfrey206 / suff.cpp
Created April 27, 2022 21:59
Suffix tree insert and search
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
using namespace std;
struct suffix_tree {
std::string suffix;
suffix_tree* child[26] = {};
int index = 0;
@dgodfrey206
dgodfrey206 / minesweeper.cpp
Last active September 7, 2024 04:06
C++14 Minesweeper Console Game
#include <iostream>
#include <unordered_set>
#include <ctime>
#include <vector>
constexpr int n = 10;
int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int dy[8] = {1, 1, 1, 0, 0, -1, -1, -1};
bool gameOver = false;
@dgodfrey206
dgodfrey206 / Board.java
Created December 25, 2019 19:31
8-Puzzle Board.java
import java.util.ArrayList;
public class Board {
private int[][] board;
private final int n;
private int hammingDist;
private int manhattanDist;
private int blankX, blankY;
// create a board from an n-by-n array of tiles,
// where tiles[row][col] = tile at (row, col)
@dgodfrey206
dgodfrey206 / addressbook.cpp
Last active December 19, 2019 04:16
Address book program I did for someone
#include <iostream>
#include <string>
#include <cstdlib>
#include <limits>
#include <locale>
#include <sstream>
#include <iomanip>
#include <cassert>
template<class T>
@dgodfrey206
dgodfrey206 / myString.java
Created November 29, 2019 19:51
myString
public class MyString {
private char[] buffer;
private MyString next = null;
private int len = 0;
public MyString(char[] data) {
buffer = data.clone();
len += data.length;
@dgodfrey206
dgodfrey206 / mile.js
Last active October 9, 2019 20:57
for MJ
function calculate() {
var total_miles = 0;
var avg_daily_miles = 0;
for (var i=1; i<=7; i++) {
var dist = +document.getElementsByName("value" + i)[0].value;
total_miles += dist;
avg_daily_miles += dist/7.0;
}
document.getElementById("totalM").value = total_miles;
document.getElementById("avgM").value = avg_daily_miles;
import java.util.*;
/*public*/ interface Cipher {
public abstract String encode(String plainText);
}
/*public*/ class ShiftN_Cipher implements Cipher {
public ShiftN_Cipher(int shifts) {
this.shifts = shifts;
}
@dgodfrey206
dgodfrey206 / sortStack.cpp
Created October 7, 2019 18:03
Sort a stack using recursion
#include <iostream>
#include <string>
#include <vector>
#include<bits/stdc++.h>
using namespace std;
void insertSorted(stack<int>& s, int e) {
stack<int> temp;
while (true) {
if (s.empty() || e >= s.top()) {
@dgodfrey206
dgodfrey206 / tofromhex.cpp
Last active September 4, 2019 01:20
Converting to and from hex
#include<bits/stdc++.h>
using namespace std;
string toHex(int n) {
string result;
while (n) {
int rem = n % 16;
result += (rem < 10) ? (rem + '0') : ('A' + rem - 10);
n /= 16;
}