This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
============================================================================ | |
Name : Dining_Philosopher.c | |
Author : | |
Version : | |
Copyright : Your copyright notice | |
Description : Hello World in C, Ansi-style | |
============================================================================ | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer