Skip to content

Instantly share code, notes, and snippets.

View kingdido999's full-sized avatar

Pengcheng Ding kingdido999

View GitHub Profile
@kingdido999
kingdido999 / mergesort.java
Created January 11, 2016 20:41
Top-down implementation of merge sort.
void mergeSort(int[] a, int[] b, int first, int last) {
if (first < last) {
int mid = (first + last) / 2;
mergeSort(a, b, first, mid - 1);
mergeSort(a, b, mid, last);
merge(a, b, first, mid, last);
copyBtoA(b, a, first, last);
}
}
@kingdido999
kingdido999 / quicksort.java
Last active January 11, 2016 19:26
A Quicksort implementation in Java which uses the first number as pivot.
/* Inspired by: http://interactivepython.org/runestone/static/pythonds/SortSearch/TheQuickSort.html */
void quickSort(int[] a, int first, int last) {
if (first < last) {
int p = partition(a, first, last); // split point
quickSort(a, first, p - 1); // sort numbers on the left side of the split point
quickSort(a, p + 1, last); // sort numbers on the right side of the split point
}
}
@kingdido999
kingdido999 / freelist.mru.c
Last active August 29, 2015 14:17
cs460-pa1
/*
* CS460
*
* This will put a buffer into MRU list. This function should be only called by
* unpinning a buffer. Since it is MRU, we always put at head position. This
* is consistent with StrategyGetBuffer where we pick also at head position.
* This is not the same as InvalidateBuffer where a buffer is surely not useful
* any more and should be put into free buffer instead.
*
* MRU是将buf插入头部,LRU是将buf插入尾部