Skip to content

Instantly share code, notes, and snippets.

View codelance's full-sized avatar

Brandon Brisbon codelance

View GitHub Profile
@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)
@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 / 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 / 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 / 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 / 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 / binary_search.java
Created December 2, 2012 01:09
Binary Search
private static int binarySearch( int[ ] a, int toFind, int low, int high )
{
if( low > high )
return -1;
int mid = ( low + high ) / 2;
if( a[ mid ] > toFind )
return binarySearch( a, toFind, mid + 1, high );
else if( a[ mid ] < toFind )
private static int gcd(int x, int y){
if( y <= x & (x%y) == 0)
return y;
else if( x < y)
return gcd(y,x);
else
return gcd(y, x % y);
}
private static int iterativegcd(int x, int y)
@codelance
codelance / fibonacci.java
Created December 2, 2012 01:10
Fibonacci
private static int gfib(int f0, int f1, int n)
{
switch( n )
{
case 0:
return f0;
case 1:
return f1;
default:
return gfib(f0,f1, n-1 ) + gfib(f0, f1, n+1);
@codelance
codelance / DataNode.java
Created December 2, 2012 01:17
Java Stack Based Linked List
public class DataNode {
/*DataNode Constructor
Description: Called when an object is instantiated
Parameters:
Object Elem : object stored as data in this class
Pre: None
Post: Initialized element