QuickSort again
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的更多相关文章
- quickSort算法导论版实现
本文主要实践一下算法导论上的快排算法,活动活动. 伪代码图来源于 http://www.cnblogs.com/dongkuo/p/4827281.html // imp the quicksort ...
- Javascript算法系列之快速排序(Quicksort)
原文出自: http://www.nczonline.net/blog/2012/11/27/computer-science-in-javascript-quicksort/ https://gis ...
- JavaScript 快速排序(Quicksort)
"快速排序"的思想很简单,整个排序过程只需要三步: (1)在数据集之中,选择一个元素作为"基准"(pivot). (2)所有小于"基准"的元 ...
- QuickSort 快速排序 基于伪代码实现
本文原创,转载请注明地址 http://www.cnblogs.com/baokang/p/4737492.html 伪代码 quicksort(A, lo, hi) if lo < hi p ...
- quicksort
快排.... void quicksort(int *a,int left,int right){ if(left >= right){ return ; } int i = left; int ...
- 随手编程---快速排序(QuickSort)-Java实现
背景 快速排序,是在上世纪60年代,由美国人东尼·霍尔提出的一种排序方法.这种排序方式,在当时已经是非常快的一种排序了.因此在命名上,才将之称为"快速排序".这个算法是二十世纪的七 ...
- 算法实例-C#-快速排序-QuickSort
算法实例 ##排序算法Sort## ### 快速排序QuickSort ### bing搜索结果 http://www.bing.com/knows/search?q=%E5%BF%AB%E9%80% ...
- python Quicksort demo
__author__ = 'student' ''' quicksort step 1, choose one pivot, such as pivot=la[0] step 2, scan the ...
- 63.如何对单链表进行快排?和数组快排的分析与对比[quicksort of array and linked list]
[本文链接] http://www.cnblogs.com/hellogiser/p/quick-sort-of-array-and-linked-list.html [题目] 单链表的特点是:单向. ...
- 这个代码怎么改??Help快速排序 quicksort
#include<stdio.h>int a[101],n;void quicksort(int left,int right){ int i,j,t,temp; if(l ...
随机推荐
- Chap 2 Representing and Manipulating Information (CS:APP)
-------------------------------------------------------------------------------------------------- A ...
- 75. Find Peak Element 【medium】
75. Find Peak Element [medium] There is an integer array which has the following features: The numbe ...
- python简单处理xml文件
Python若是想从xml里读点信息,用BeautifulSoup可能会容易一点,但是如果要修改xml,BeatifulSoup就搞不定了,其实直接用lxml就好. from lxml import ...
- finsh初步
一. finsh在RT-Thread中被设计成一个独立的线程,它试图从外部设备中获得用户的输入,然后对用户命令进行解析执行. 正确使用finsh需要一个关联过程: rt_hw_board_init() ...
- IOS项目开发中的文件和文件夹操作
+ (NSFileManager *)getNSFileManager { // iNSFileManager是一个静态变量 if (!iNSFileManager) { iNSFileManager ...
- Photoshop脚本之储存图片
function saveEPS( doc, saveFile ) { var saveOptions = new EPSSaveOptions( ); saveOptions.encoding = ...
- ASP.NET动态网站制作(29)-- 正则
前言:继续讲框架,然后介绍正则的相关知识. 内容: 1.封装分页方法,方便以后调用:响应的CSS代码也可以封装. 2.WEB层里面的页面名称不要和model和dal里面的名称相同. 3.两个表联合查询 ...
- windows文件打包命令
copy /Y partition.bin /b + qcsblhd_cfgdata.bin /b + qcsbl.bin /b + oemsbl.bin /b + fat.amss.bin /b + ...
- 一些常用的html css整理--文本长度截取
div+css设置列表div超出部分显示...(单行文本) width:200px; //指定宽度: overflow:hidden; //将超出内容隐藏 text-overflow:ellipsis ...
- centos6.4下安装mysql5.7.18
1.安装前工作 在安装前需要确定现在这个系统有没有 mysql,如果有那么必须卸载(在 centos7 自带的是 mariaDb 数据库,所以第一步是卸载数据库). 卸载系统自带的Mariadb: 查 ...