Skip to content

Instantly share code, notes, and snippets.

@aaronjwood
aaronjwood / HM.java
Last active October 13, 2017 17:27
Hash map using an ArrayList
import java.util.ArrayList;
class HM<K, V> {
private static class HashNode<K, V> {
private K key;
private V value;
private HashNode<K, V> next;
HashNode(K key, V value) {
this.key = key;
@aaronjwood
aaronjwood / GraphBFS.java
Created October 6, 2017 15:48
Breadth first search of a graph
import java.util.LinkedList;
import java.util.Queue;
class GraphBFS {
private int vertices;
private LinkedList<Integer> adjacency[];
GraphBFS(int v) {
vertices = v;
adjacency = new LinkedList[v];
@aaronjwood
aaronjwood / GraphDFS.java
Created October 6, 2017 15:34
Depth first search of a graph
import java.util.LinkedList;
import java.util.Stack;
class GraphDFS {
private int vertices;
private LinkedList<Integer> adjacency[];
GraphDFS(int v) {
vertices = v;
adjacency = new LinkedList[v];
@aaronjwood
aaronjwood / Queue.java
Created September 25, 2017 19:53
Queue using a linked list
class Queue<T> {
private static class Node<D> {
private D data;
private Node<D> previous;
private Node<D> next;
private Node(D data) {
this.data = data;
}
@aaronjwood
aaronjwood / extract.c
Created February 12, 2017 07:37
Store two integers in a single variable with bitwise operations.
#include <stdio.h>
int main(void) {
int num1;
int num2;
printf("Feed me two numbers and I will store them in a single variable: ");
if (scanf("%d %d", &num1, &num2) != 2) {
printf("Enter two numbers\n");
@aaronjwood
aaronjwood / Stack.java
Last active February 12, 2017 06:54
Stack using a linked list
public class Stack<E> {
private class Node<V> {
private V data;
private Node<V> next;
Node(V data) {
this.data = data;
}
}
@aaronjwood
aaronjwood / fib.go
Created February 12, 2017 05:46
Fibonacci sequence
package main
import (
"flag"
"fmt"
)
// Time: O(2^n)
// Space: O(n)
func FibRecursive(n uint64) uint64 {
@aaronjwood
aaronjwood / overflow.c
Last active January 8, 2017 21:50
Stack buffer overflow
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
char buff[15];
int auth = 0;
printf("\nEnter password: ");
gets(buff);
@aaronjwood
aaronjwood / swap.go
Created November 2, 2016 03:42
Comparing variable swap with XOR and with temporary variable.
package main
func Swap(a, b int) int {
a = a ^ b
b = b ^ a
a = a ^ b
return a
}
@aaronjwood
aaronjwood / BinarySearchTree.cs
Created February 15, 2016 05:57
Binary search tree implementation in C#
using System;
using System.Diagnostics;
namespace BinarySearchTree
{
class Node
{
public int value;
public Node left;
public Node right;