摘要: 快速排序学习的这个版本的特点是:1.原地排序2.采用了分治法3.采用递归伪代码:quick_sort(arr, low, high)i <-low, j <- high;mid <- (i+j)/2;实现从小到大排//设置哨兵pivot <- arr[mid];while i<= j从左向右寻找大于哨兵的元素,当然小于哨兵的就是无需排序的while arr[i] < pivot ++i;从右向左寻找小于哨兵元素while arr[j] > pivot --j;把寻找到的无序值进行交换并更新i,jif i <= j swap(arr[i],arr[ 阅读全文
posted @ 2011-08-14 22:32 hailong 阅读(346) 评论(0) 推荐(1) 编辑
摘要: 伪代码:int put list[1->n];for i <- n to 1 for j = 0 to i-1 if list[j]>list[j+1] swap(list[j],list[j+1])C++实现:#include<iostream>//交换数据inline void my_swap(int &a, int &b){ int temp = a; a = b; b =temp;}//冒泡排序void bubble_sort(int *arr,int n){ for (int i = n-1; i >= 0; --i) for (i 阅读全文
posted @ 2011-08-14 22:01 hailong 阅读(284) 评论(0) 推荐(0) 编辑
摘要: 快速排序Quicksort is a fast sorting algorithm, which is used not only for educational purposes, but widely applied in practice. On the average, it has O(n log n) complexity, making quicksort suitable for sorting big data volumes. The idea of the algorithm is quite simple and once you realize it, you can 阅读全文
posted @ 2011-08-14 17:01 hailong 阅读(208) 评论(0) 推荐(0) 编辑