Chinaunix首页 | 论坛 | 博客
  • 博客访问: 620226
  • 博文数量: 69
  • 博客积分: 1891
  • 博客等级: 上尉
  • 技术积分: 1359
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-20 23:38
文章分类

全部博文(69)

文章存档

2012年(46)

2011年(23)

分类: Python/Ruby

2011-09-18 23:06:08

  1. sort([])->[];
  2. sort([Privot|Rest])->
  3.                 {Smaller,Bigger}=spilt(Privot,Rest),
  4.                 lists:append(sort(Smaller),[Privot|sort(Bigger)]).

  5. spilt(Privot,L)->
  6.         spilt(Privot,L,[],[]).

  7. spilt(Privot,[],Smaller,Bigger)->
  8.         {Smaller,Bigger};
  9. spilt(Privot,[H|T],Smaller,Bigger) when H<Privot->
  10.         spilt(Privot,T,[H|Smaller],Bigger);
  11. spilt(Privot,[H|T],Smaller,Bigger) when H>=Privot->
  12.         spilt(Privot,T,Smaller,[H|Bigger]).

  13. qsort(X)->
  14.         qsort(X,[]).
  15. qsort([Pivot|Rest],Tail)->
  16.         {Smaller,Bigger}=spilt(Pivot,Rest),
  17.         qsort(Smaller,[Pivot|qsort(Bigger,Tail)]);
阅读(2005) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~