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 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); | |
} | |
} |
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
/* 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 | |
} | |
} |
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
/* | |
* 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插入尾部 |