按序打印
力扣上的一道题,三个线程按照顺序分别打印出来one、tow、three: 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950class Foot { private val flag:AtomicInteger = AtomicInteger(0) @Throws(InterruptedException::class) fun first(printFirst: Runnable) { // printFirst.run() outputs "first". Do not change or remove this line. printFirst.run() flag.incrementAndGet() } @Throws(InterruptedException::class) fun second(printSeco...
朝花夕拾之几大基础排序算法
算法从来不是死记硬背,而是要知道它背后需要解决什么样的问题,为什么这样设计, 选择排序其实就是挨个查找最小元素的索引,然后交换之。先看图: 12345678910111213141516template<typename T>void selectionSort(T arr[], int n) { for (int i = 0; i < n; i++) { //寻找在[i,n)之间的最小值的索引 int minIndex = i; for (int j = i+1; j < n; j++) { if (arr[j] < arr[minIndex]) { minIndex = j; } } swap(arr[i], arr[minIndex]); }} 插入排序 1234567891011121314template<typename T > void insertSort(T arr[], int n) { ...





