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 random | |
def randSelect (array, rank): | |
print("Looking for value with rank %s in the array:" % rank) | |
print(array) | |
i = random.randint(0, len(array)-1) | |
array, pos = inPlacePartition(array, i) | |
direction = getDirection(rank, pos) | |
print("Selected %s as the pivot; its rank is %s; Thus, we recurse on %s" % (array[0], pos, direction)) |
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 <functional> | |
#include <iostream> | |
void print(const int &i) | |
{ | |
std::cout << i << '\n'; | |
} | |
int main() | |
{ |
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
var insert = function(array, rightIndex, value) { | |
var i = 0; | |
for (var j = 1; array[j] < array[i]; j++) { | |
var tmp = array[i]; | |
array[i] = array[j]; | |
array[j] = tmp; | |
i++; | |
break; | |
} | |
for (i = rightIndex; value < array[i] && i >= 0; 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
/* Returns either the index of the location in the array, | |
or -1 if the array did not contain the targetValue */ | |
var doSearch = function(array, targetValue) { | |
var min = 0; | |
var max = array.length - 1; | |
var guess; | |
var guessCount = 0; | |
while (max >= min) { | |
guessCount ++; | |
guess = Math.floor((min + max)/2); |
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
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed Dec 9 14:55:43 2015 | |
This script is to convert the txt annotation files to appropriate format needed by YOLO | |
@author: Guanghan Ning | |
Email: [email protected] | |
""" | |
import os | |
from os import walk, getcwd |
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
void insertionSort(Array * S, int n) { | |
if (n <= 1) return; // 1. Base case: Return if last (null) mem point | |
insertionSort(S, n-1); // 2. recursively go through each element in array, starting with last | |
int last = S[n-1]; // 3. set current last element | |
int j = n-2; // 4. Run through each previous element | |
while (j >= 0 && S[j] > last) { // 5. While that element is bigger than the last element | |
S[j+1] = S[j]; // 6. Move its location forward in the array. | |
j--; // 7. Go on to the next element in array. | |
} | |
S[j+1] = last; // 8. set last element to the final point in the array. |
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
// Simple Splay | |
#include<iostream> | |
using namespace std; | |
template<class T> | |
struct Node { | |
T value; | |
Node *l, *r, *p; |
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
#ifndef SPLAY_TREE_H | |
#define SPLAY_TREE_H | |
#include <utility> | |
#include <iostream> | |
#include "Array.h" | |
#include "bst.h" | |
#include <cassert> | |
using namespace std; |
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
// If exp is even, split in half twice and call each recursively | |
// otherwise, split in half twice and call each recursively AND multiply x | |
// Questions: | |
// What if exponent is 1? -- Then it will return x*1*1 | |
// What if exponent is 3+? -- If even, split. If odd, multiply next split value to x | |
int power(int base, int exponent) { | |
if (exponent == 0) return 1; | |
else if (exponent%2 == 0) // if even |
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
// Assume a linked list object with mHead, and mTail LLNodes, and mSize for size of list | |
// If there is a cycle, the linked list would never break out of a while loop. | |
// So if it exceeds the length of the list, we know there's a cycle somewhere | |
bool isCycle() { | |
if(mHead == NULL) return false; | |
node * n = mHead; | |
int lSize = mSize; | |
while(true) { |
NewerOlder