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
//answer to google 2011 school interview at zju | |
int quick_partition(int array[], int start, int end) | |
{ | |
int x = array[end]; | |
int i = start - 1; | |
int tmp; | |
for (int j=start; j<end; ++j) | |
{ | |
if (array[j]<=x) | |
{ |
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
# ~/.osx — http://mths.be/osx | |
############################################################################### | |
# General UI/UX # | |
############################################################################### | |
# Set computer name (as done via System Preferences → Sharing) | |
scutil --set ComputerName "MacBookPro" | |
scutil --set HostName "MacBookPro" | |
scutil --set LocalHostName "MacBookPro" |
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
/** Divide : Partition the array A[low....high] into two sub-arrays | |
* A[low....j-1] and A[j+1...high] such that each element | |
* of A[low....j-1] is less than or equal to A[j], which | |
* in turn is is less than or equal to A[j+1...high]. Compute | |
* the index j as part of this partitioning procedure. | |
* Conquer : Sort the two sub-arrays A[low....j-1] and A[j+1....high] | |
* by recursive calls to quicksort | |
**/ | |
#include<stdio.h> |
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
//quick sort | |
#include<stdio.h> | |
void quicksort(int*arr,int left, int right); | |
int partition(int *arr,int left,int right); | |
int main() | |
{ | |
int arr[6]={5,4,1,2,8,3}; | |
int 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
void * safe_malloc(size_t const size) | |
{ | |
void * p = malloc(size); | |
if (p == NULL) { | |
fprintf(stderr, "Out of memory\n"); | |
exit(1); | |
} | |
return p; |