Skip to content

Instantly share code, notes, and snippets.

@ruanchao
ruanchao / safealloc.c
Created July 20, 2012 15:02 — forked from alexpirine/safealloc.c
Safe memory allocation in C
void * safe_malloc(size_t const size)
{
void * p = malloc(size);
if (p == NULL) {
fprintf(stderr, "Out of memory\n");
exit(1);
}
return p;
@ruanchao
ruanchao / quick.c
Created August 14, 2012 08:57 — forked from rohit-nsit08/quick.c
quick sort
//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;
@ruanchao
ruanchao / quick_sort.c
Created August 14, 2012 08:58 — forked from mbalayil/quick_sort.c
Quick Sort using recursion in C
/** 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>
@ruanchao
ruanchao / gist:3432022
Created August 23, 2012 03:43 — forked from brandonb927/osx-for-hackers.sh
OSX for Hackers: Mountain Lion Edition
# ~/.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"
@ruanchao
ruanchao / intersection.c
Created September 4, 2012 03:41 — forked from shihongzhi/intersection.c
求交集
//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)
{