QUICKSORT OPINION
来源:互联网 发布:软件商城下载 编辑:程序博客网 时间:2024/05/18 00:34
QuickSort
QuickSorting is a typically divide and conquer algorithm.
It continously divides an array into two subarrays until its of each array come into a right order.
The algorithm needs a pivot ,a left point and a right point to be the standard and mark the comparison location.
The pivot is always the middle element of each array . The value of pivot is the reference which is never changed in this comparison . After reordering the array, the number less than pivot is on the left of pivot and the number greater than pivot is on the right of pivot.
To finish reordering , we should use the left and right point .
When we meet the number greater than the pivot on the left , we should copy the number to the pivot location and replace the greater one position with pivot location , then start the point moving on the right side and go on until it completes it.
The weakness is that once you come back to the left or right point , you need to compare the last exchanged left or right one again. You can imagine the picture with 3 arrow of left right and pivot . And before the arrow of left and right exchanging , the pivot arrow alternatively jump between the left and right after one of those moving(– or ++)
The method of dividing and conquering is evidenced by recursively using sorting algorithm to process the divider array.
int Partitioning(int array[],int division,int left,int right){ int temp = array[division]; while(1){ while(array[left] < temp){ left++; } if(left >= right) break; array[division] = array[left]; division = left; while(array[right] >= temp){ right--; } if(left >= right) break; array[division] = array[right]; division = right; } array[division] = temp; return division;}void Sort(int array[],int left,int right){ if(left >= right) return; int division = (left + right)/2; int part = Partitioning(array,division,left,right); Sort(array,left,part-1); Sort(array,part+1,right);}
- QUICKSORT OPINION
- Opinion mining
- Quicksort
- QuickSort
- quicksort
- quicksort
- QuickSort
- QuickSort
- QuickSort
- QuickSort
- QuickSort
- QuickSort
- quicksort
- QuickSort
- QuickSort
- QuickSort
- quicksort
- quicksort
- 解决VS2010创建工程时弹出“创建或打开C++浏览数据库文件 发生错误”的问题"
- 解决Pycharm里远程调试缺乏DISPLAY环境变量的TkAgg报错
- 剑指offer 08 旋转数组的最小数字
- 转载CSDN博客
- 使用生产者消费者解决海量数据的处理与相关优化
- QUICKSORT OPINION
- Mockito的使用
- java泛型(一)、泛型的基本介绍和使用
- Harris角点检测实现详解
- Arduino智能小车——测试篇
- 使用GROUP BY得到 极端的记录
- 爬虫学习(三) Scrapy框架入门与豆瓣电影爬虫
- RILD
- 计蒜客-跳跃游戏(贪心)