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
#First partition the input array into two groups | |
# Partitioning alogorithm creates smaller array with elements on left and | |
# right being smaller and greater than the pivot | |
def partiton(a, left, right): | |
i = left + 1 # Initialiase i to one more assuming pivot is at position left | |
pivot = a[left] | |
for j in range(left+1, right+1): #Iterate over the remaining array | |
if (a[j] < pivot): |
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<iostream> | |
#include <list> | |
using namespace std; | |
class Graph { | |
int V; | |
list <int> * adj; | |
void DFSUtil(int v, bool visited[]); // A function used by DFS | |
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
static inline BOOL checkIfEmpty(id obj) { | |
return thing == nil || | |
([obj respondsToSelector:@selector(length)] && [(NSData *)obj length] == 0) || | |
([obj respondsToSelector:@selector(count)] && [(NSArray *)obj count] == 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
# This is written after refering the CLRS book and hints from the site http://en.literateprograms.org/Merge_sort_(Python) | |
#The merge method takes in the two subarrays and creates a output array | |
def merge(left, right): | |
result = [] | |
i , j = 0 , 0 | |
while i < len (left) and j < len (right): # iterate through both arrays and arrange the elements in sorted order | |
if left[i] <= right [j]: | |
result.append(left[i]) | |
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
for (NSString *familyName in [UIFont familyNames]) { | |
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) { | |
NSLog(@"%@", fontName); | |
} | |
} |
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
from random import randint | |
board = [] | |
for x in range(5): | |
board.append(["O"] * 5) | |
def print_board(board): | |
for row in board: | |
print " ".join(row) |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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 <iostream> | |
using namespace std; | |
#include <stdlib.h> /* qsort */ | |
int compare (const void * a, const void * b) { | |
return ( *(int*)a - *(int*)b ); | |
} | |
int main4() | |
{ |
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 <iostream> | |
using namespace std; | |
#include <stdlib.h> /* qsort */ | |
int compare (const void * a, const void * b) { | |
return ( *(int*)a - *(int*)b ); | |
} | |
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
def calculateLevenSteninDistance(a,b): | |
if not a: return len(b) | |
if not b: return len(a) | |
return min(calculateLevenSteninDistance(a[1:], b[1:])+(a[0] != b[0]), calculateLevenSteninDistance(a[1:], b)+1, calculateLevenSteninDistance(a, b[1:])+1) |
NewerOlder