A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© qqhao01 高级黑马   /  2013-9-5 21:36  /  1097 人查看  /  6 人回复  /   1 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 qqhao01 于 2013-9-6 08:54 编辑

各位大神 能帮我按效率的高低排一下排序的顺序么 这里有些不太明白  谢谢各位了

评分

参与人数 1技术分 +1 收起 理由
黄兴旺 + 1

查看全部评分

6 个回复

倒序浏览
本帖最后由 常在河边走_ 于 2013-9-5 21:55 编辑

快速排序> 希尔排序 >鸡尾酒排序>冒泡排序>选择排序
回复 使用道具 举报
常在河边走_ 发表于 2013-9-5 21:47
快速排序> 希尔排序 >鸡尾酒排序>冒泡排序>选择排序

不是说效率最快的是希尔排序么  还有鸡尾酒排序是什么啊 没听过 能说一下么
回复 使用道具 举报
本帖最后由 常在河边走_ 于 2013-9-5 22:02 编辑
qqhao01 发表于 2013-9-5 21:57
不是说效率最快的是希尔排序么  还有鸡尾酒排序是什么啊 没听过 能说一下么 ...

  •                 鸡尾酒排序,也就是定向冒泡排序, 鸡尾酒搅拌排序, 搅拌排序 (也可以视作选择排序的一种变形), 涟漪排序, 来回排序,
  •                 是冒泡排序的一种变形。此算法与冒泡排序的不同处在于排序时是以双向在序列中进行排序。
  •                 */
  •                 public function cocktailSortArr(result:Array):Array {
  •                         var i:int = 0;
  •                         var n:int = result.length;
  •                         var top:int = n - 1;
  •                         var bottom:int = 0;
  •                         var swapped:Boolean = true;
  •                         while(swapped) { // if no elements have been swapped, then the list is sorted
  •                                 swapped = false;
  •                                 var temp:Number;
  •                                 for(i = bottom; i < top;i++) {
  •                                         if(result > result[i + 1]) {  // test whether the two elements are in the correct order
  •                                                 temp = result;// let the two elements change places
  •                                                 result = result[i + 1];
  •                                                 result[i + 1] = temp;
  •                                                 swapped = true;
  •                                         }
  •                                 }
  •                                 // decreases top the because the element with the largest value in the unsorted
  •                                 // part of the list is now on the position top
  •                                 top = top - 1;
  •                                 for(i = top; i > bottom;i--) {
  •                                         if(result < result[i - 1]) {
  •                                                 temp = result;
  •                                                 result = result[i - 1];
  •                                                 result[i - 1] = temp;
  •                                                 swapped = true;
  •                                         }
  •                                 }
  •                                 // increases bottom because the element with the smallest value in the unsorted
  •                                 // part of the list is now on the position bottom
  •                                 bottom = bottom + 1;
  •                         }
  •                         return result;
  •                 }

评分

参与人数 1技术分 +1 收起 理由
黄兴旺 + 1

查看全部评分

回复 使用道具 举报
效率最高的是希尔排序
回复 使用道具 举报
张亚军 发表于 2013-9-5 23:02
效率最高的是希尔排序

那应该怎么排啊  选择排序 效率是最低 的么
回复 使用道具 举报
希尔排序 >快速排序>鸡尾酒排序>冒泡排序>选择排序

快速排序叫快速,但是其实没有希尔排序效率高..
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马