Skip to content

Instantly share code, notes, and snippets.

View codelance's full-sized avatar

Brandon Brisbon codelance

View GitHub Profile
@codelance
codelance / Heap.java
Created December 2, 2012 01:03
Huffman Tree
public class Heap<E extends Comparable> {
private java.util.ArrayList<E> list = new java.util.ArrayList<E>();
/** Create a default heap */
public Heap() {
}
/** Create a heap from an array of objects */
public Heap(E[] objects) {
for (int i = 0; i < objects.length; i++)
@codelance
codelance / SelectionSort.java
Created December 2, 2012 00:57
Java Selection Sort
public class SelectionSort {
/** The method for sorting the numbers */
/*
* Worst Case: O(n^2)
*/
public static void selectionSort(double[] list) {
for (int i = 0; i < list.length - 1; i++) {//Runs n times
// Find the minimum in the list[i..list.length-1]
//Get each element in the list for comparisons
@codelance
codelance / MergeSort.java
Created December 2, 2012 00:57
Java Merge Sort
public class MergeSort {
/** The method for sorting the numbers */
/*
* Worst Case: O(n log n)
*/
public static void mergeSort(int[] list) {
if (list.length > 1) {
// Merge sort the first half
@codelance
codelance / InsertSort.java
Created December 2, 2012 00:56
Java Insert Sort
public class InsertionSort {
/** The method for sorting the numbers */
/*
* Worst Case: O(n^2)
*/
public static void insertionSort(double[] list) {
for (int i = 1; i < list.length; i++) { ///Runs n times
/** insert list[i] into a sorted sublist list[0..i-1] so that
@codelance
codelance / Dining_Philosopher.c
Created December 2, 2012 00:41
Dining Philosopher
/*
============================================================================
Name : Dining_Philosopher.c
Author :
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/
@codelance
codelance / client.c
Created December 2, 2012 00:35
Client Socket Example
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdlib.h>
#include <string.h>
// error handling
void error(char *msg)