Skip to content

Instantly share code, notes, and snippets.

@ruanchao
ruanchao / gist:2628718
Created May 7, 2012 16:16
Java:makefile
GS = -g
JC = javac
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $*.java
CLASSES = \
Server.java \
Client.java \
@ruanchao
ruanchao / list.c
Created June 26, 2012 06:24
Link list - C
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
typedef struct node_t
{
int value;
struct node_t *next;
}node_t;
@ruanchao
ruanchao / queue.c
Created July 3, 2012 11:30
Doubly Linked list C
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#ifndef QUEUE_H
#define INPUT_BUFFER_SIZE 100
#define OP_QUEUE_ENQUEUE 0
#define OP_QUEUE_DEQUEUE 1
@ruanchao
ruanchao / bubbleSort.c
Created July 7, 2012 04:15
Bubble sort - C
#include <stdio.h>
void bubbleSort(int arr[], int count)
{
int i = count, j;
int temp;
while(i > 0)
{
for(j = 0; j < i - 1; j++)
@ruanchao
ruanchao / bst.c
Created July 11, 2012 06:55
Binary search tree - C
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#ifndef _BST_H
#define _BST_H
#define END 0
#define INSERT 1
@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 / safe_function.c
Created August 23, 2012 04:49
Safe-memory-functions
/*
* safe_malloc ()
*
* Call calloc () and abort if the specified amount of memory cannot be
* allocated.
*/
void *
safe_malloc(size_t size)
{