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 subprocess | |
import re | |
def get_last_label(): | |
output = subprocess.check_output(["cm", "find", "label", "order by date desc", "limit 2", "--format={changeset}", "on repository 'dmo-softbank-smartcity-envisioning'", "--nototal"]) | |
changesetids = output.decode("utf-8").splitlines() | |
if changesetids: | |
return changesetids[-1] | |
else: | |
return None |
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
// METHOD 1: Least efficient. O(n) time complexity. | |
int LoopAndTest() | |
{ | |
int a = 3, b = 5; | |
int sum = 0; | |
int limit = 1000; | |
for( int i = 0; i < limit; ++i ) | |
{ | |
if( i % a == 0 || i % b == 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
// METHOD 1: Least efficient. O(n) time complexity. | |
int LoopAndTestMethod() | |
{ | |
int sum = 0; | |
int a = 1, b = 1, c = a + b; | |
int limit = 4000000; | |
while( c < limit ) | |
{ | |
if( c % 2 == 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
template<class T> | |
void SelectionSort( T* arr, int n ) | |
{ | |
for( int slot = 0; slot < n - 1; ++slot ) | |
{ | |
int minIdx = slot; | |
for( int testIdx = slot + 1; testIdx < n; ++testIdx ) | |
{ | |
if( arr[testIdx] < arr[minIdx] ) | |
minIdx = testIdx; |
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
template<class T> | |
void MergeSort( T* arr, int startIdx, int endIdx ) | |
{ | |
if( startIdx < endIdx ) | |
{ | |
int midIdx = startIdx + ( endIdx - startIdx ) / 2; | |
MergeSort( arr, startIdx, midIdx ); | |
MergeSort( arr, midIdx + 1, endIdx ); | |
Merge( arr, startIdx, midIdx, endIdx ); | |
} |
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
template<class T> | |
void MergeSort( T* arr, int n ) | |
{ | |
if( n < 2 ) | |
return; | |
int leftSize = n / 2; | |
int rightSize = n - leftSize; | |
T* left = new int[leftSize]; |
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
template<class T> | |
void BubbleSort( T* arr, int n ) | |
{ | |
for( int pass = 1; pass < n; ++pass ) | |
{ | |
bool didSwap = false; | |
for( int i = 0; i < n - pass; ++i ) | |
{ | |
if( arr[i] > arr[i + 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
template<class T> | |
void InsertionSort( T* arr, int n ) | |
{ | |
for( int pass = 1; pass < n; ++pass ) | |
{ | |
int slot = pass; | |
T val = arr[slot]; | |
while( slot > 0 && val < arr[slot - 1] ) | |
{ | |
arr[slot] = arr[slot - 1]; |