I wrote a blog about Quick Sort before. Let's talk more about it.

  If you don't think that the implementation in the blog mentioned is easy to remember and understand.

You can send your implementation to me by E-mail(lxw.ucas@gmail.com). Now let's look at some other

implementations that are not so amazing:

  A new implementation in python is shown here:

def qs(arr):
if not arr:
return []
low = []
high = []
for x in arr[1:]:
if x <= arr[0]:
low.append(x)
else:
high.append(x)
low = qs(low)
high = qs(high)
return low + arr[:1] + high # low + arr[0] + high is NOT OK! --> ERROR PROMPT: 'can only concatenate list(not int) to list'

  It seemed not so amazing and easy to understand as the former one. But it's ok as well. : ) Let's look

at another new implementation in python:

def quickSort(arr, start, end):
if start >= end: # EXIT
return
i = start
j = end
target = arr[i]
while i < j:
while arr[i] <= target and i < end:
i += 1
while arr[j] > target and j > start:
j -= 1
if i < j:
arr[i], arr[j] = arr[j], arr[i]
arr[start] = arr[j]
arr[j] = target
quickSort(arr, start, j - 1)
quickSort(arr, j + 1, end)

  Now, which way of implementation do you prefer? Do you think the implementation in the blog mentioned

is easy to understand and remember?

QuickSort again的更多相关文章

  1. quickSort算法导论版实现

    本文主要实践一下算法导论上的快排算法,活动活动. 伪代码图来源于 http://www.cnblogs.com/dongkuo/p/4827281.html // imp the quicksort ...

  2. Javascript算法系列之快速排序(Quicksort)

    原文出自: http://www.nczonline.net/blog/2012/11/27/computer-science-in-javascript-quicksort/ https://gis ...

  3. JavaScript 快速排序(Quicksort)

    "快速排序"的思想很简单,整个排序过程只需要三步: (1)在数据集之中,选择一个元素作为"基准"(pivot). (2)所有小于"基准"的元 ...

  4. QuickSort 快速排序 基于伪代码实现

    本文原创,转载请注明地址 http://www.cnblogs.com/baokang/p/4737492.html 伪代码 quicksort(A, lo, hi) if lo < hi p ...

  5. quicksort

    快排.... void quicksort(int *a,int left,int right){ if(left >= right){ return ; } int i = left; int ...

  6. 随手编程---快速排序(QuickSort)-Java实现

    背景 快速排序,是在上世纪60年代,由美国人东尼·霍尔提出的一种排序方法.这种排序方式,在当时已经是非常快的一种排序了.因此在命名上,才将之称为"快速排序".这个算法是二十世纪的七 ...

  7. 算法实例-C#-快速排序-QuickSort

    算法实例 ##排序算法Sort## ### 快速排序QuickSort ### bing搜索结果 http://www.bing.com/knows/search?q=%E5%BF%AB%E9%80% ...

  8. python Quicksort demo

    __author__ = 'student' ''' quicksort step 1, choose one pivot, such as pivot=la[0] step 2, scan the ...

  9. 63.如何对单链表进行快排?和数组快排的分析与对比[quicksort of array and linked list]

    [本文链接] http://www.cnblogs.com/hellogiser/p/quick-sort-of-array-and-linked-list.html [题目] 单链表的特点是:单向. ...

  10. 这个代码怎么改??Help快速排序 quicksort

    #include<stdio.h>int a[101],n;void quicksort(int left,int right){     int i,j,t,temp;     if(l ...

随机推荐

  1. 解决js下跳转无referer的方法

    HTTP Header referer这玩意主要是告诉人们我是从哪儿来的,就是告诉人家我是从哪个页面过来的,可以用于统计访问本网站的用户来源,也可以用来防盗链.获取这个东西最好的方式是js,如果在服务 ...

  2. css制作的各种图形

    1.六角形的制作: 代码: #star-six{ height:0; width:0; border-bottom:100px solid red; border-left: 50px solid t ...

  3. Flex Air应用程序更改任务栏图标

    Air应用程序中相关图标更改的方法: 1.安装后的应用程序图标和运行时的任务栏图标 这两个是一起的,通过更改配置文件application.xml中的icon节点,分别针对不同大小进行设置,未设置的会 ...

  4. 关于python ide

    关于python ide: 在本机上正经写代码: PyCharm,社区版免费,专业版 $199 每年. 在本机上写几行脚本: ipython 或者 pyipython. 在服务器调试的时候微调代码:v ...

  5. wp8页面导向

    一般打开的是MainPage.xaml需要打开另一个页面的时候,用NavigationService.Navigate(uri);当然uri要配置是相对路径还是绝对路径Uri uri = new Ur ...

  6. abp 中wangEditor-angular 的使用

    主要是上传图片的配置. (function () { if (typeof angular === 'undefined') { return; } angular.module('editorCon ...

  7. Unity3D学习笔记——NGUI之UIGrid

    UIGrid:这个组件可以轻松的让你排列你的组件,并且在运行或是编辑的时候都可以. 效果图如下: 一:使用步骤 1.选择一个panel然后右键Create——Grid 2.为Grid创建几个子Spri ...

  8. git的优秀教程

    1.csdn地址:http://blog.csdn.net/qq_15037231/article/details/73864293 2.廖雪峰的git教程  地址:https://www.liaox ...

  9. Apache JMeter录制HTTPS的方法及测试中常见问题解决

    Jmeter录制https请求,录制不到的常见解决方案: cmd java -version 显示为1.7 以jdk1.7为例,打开\Java\jre7\lib\security 中的,java.se ...

  10. IOS开发UI篇之──自定义加载等待框(MBProgressHUD)

    本文转载至 http://blog.csdn.net/xunyn/article/details/8064984   原文地址http://www.189works.com/article-89289 ...