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
package main | |
import ( | |
"encoding/csv" | |
"fmt" | |
"io" | |
"io/ioutil" | |
"os" | |
"path/filepath" | |
"strings" |
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
import UIKit | |
enum ColorComponents { | |
case RGB(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) | |
case HSB(hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat) | |
func color() -> UIColor { | |
switch self { | |
case .RGB(let redValue, let greenValue, let blueValue, let alphaValue): | |
return UIColor(red: redValue/255.0, green: greenValue/255.0, blue: blueValue/255.0, alpha: alphaValue) |
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
/** | |
* Sorts the specified array of objects using the quick sort | |
* algorithm. | |
*/ | |
public static <T extends Comparable<? super T>> void quickSort (T[] data, int min, int max) | |
{ | |
int indexofpartition; | |
if (max - min > 0) | |
{ |
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
/** | |
* Sorts the specified array of objects using the merge sort | |
* algorithm. | |
*/ | |
public static <T extends Comparable<? super T>> void mergeSort (T[] data, int min, int max) | |
{ | |
T[] temp; | |
int index1, left, right; | |
//Return on list of length one |
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
/** | |
* Sorts the specified array of objects using an insertion | |
* sort algorithm. | |
*/ | |
public static <T extends Comparable<? super T>> void insertionSort (T[] data) | |
{ | |
for (int index = 1; index < data.length; index++) | |
{ | |
T key = data[index]; | |
int position = index; |
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
/** | |
* Searches the specified array of objects using a binary search | |
* algorithm. | |
*/ | |
public static <T extends Comparable<? super T>> boolean binarySearch (T[] data, int min, int max, T target) | |
{ | |
boolean found = false; | |
int midpoint = (min + max) / 2; //Determine the midpoint | |
if (data[midpoint].compareTo(target) == 0) |
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
/** | |
* Sorts the specified array of integers using the selection | |
* sort algorithm. | |
*/ | |
public static <T extends Comparable<? super T>> void selectionSort (T[] data) | |
{ | |
int min; | |
T temp; | |
for (int index = 0; index < data.length-1; index++) |