<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body> <script type="text/javascript">
Array.prototype.bubble_sort = function(){
var i, j, temp;
for (i = 0; i < this.length - 1; i++) {
for (j = 0; j < this.length - 1 - i; j++) {
if(this[j] > this[j + 1]){
temp = this[j];
this[j] = this[j + 1];
this[j + 1] = temp;
}
};
};
return this;
} Array.prototype.bubble_sort2 = function(){
var i, j, temp;
for (i = 0; i < this.length - 1; i++) {
for (j = 0; j < this.length - 1 - i; j++) {
if(this[j] < this[j + 1]){
temp = this[j];
this[j] = this[j + 1];
this[j + 1] = temp;
}
};
};
return this;
} var num = [22, 34, 3, 32, 82, 55, 89, 50, 37, 5, 64, 35, 9, 70];
num.bubble_sort();
for (var i = 0; i < num.length; i++)
document.body.innerHTML += num[i] + " "; document.body.innerHTML += "<br>"; num.bubble_sort2();
for (var i = 0; i < num.length; i++)
document.body.innerHTML += num[i] + " "; </script> </body>
</html>

Bubble Sort的更多相关文章

  1. Java中的经典算法之冒泡排序(Bubble Sort)

    Java中的经典算法之冒泡排序(Bubble Sort) 神话丿小王子的博客主页 原理:比较两个相邻的元素,将值大的元素交换至右端. 思路:依次比较相邻的两个数,将小数放在前面,大数放在后面.即在第一 ...

  2. Bubble Sort (5775)

    Bubble Sort Problem Description   P is a permutation of the integers from 1 to N(index starting from ...

  3. Bubble Sort [ASM-MIPS]

    # Program: Bubble sort # Language: MIPS Assembly (32-bit) # Arguments: 5 unordered numbers stored in ...

  4. HDU 5775 Bubble Sort(冒泡排序)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  5. 2016 Multi-University Training Contest 4 Bubble Sort(树状数组模板)

    Bubble Sort 题意: 给你一个1~n的排列,问冒泡排序过程中,数字i(1<=i<=n)所到达的最左位置与最右位置的差值的绝对值是多少 题解: 数字i多能到达的最左位置为min(s ...

  6. 快速幂取模 POJ 3761 bubble sort

    题目传送门 /* 题意:求冒泡排序扫描k次能排好序的全排列个数 数学:这里有一个反序列表的概念,bj表示在j左边,但大于j的个数.不多说了,我也是看网上的解题报告. 详细解释:http://blog. ...

  7. 冒泡排序(Bubble Sort)

    常见的排序算法有Bubble Sort.Merge Sort.Quick Sort 等,所有排序算的基本法思想都是把一个无限大的数据规模通过算法一步步缩小,指导最后完成排序. 这里分享一下Buuble ...

  8. [算法] 冒泡排序 Bubble Sort

    冒泡排序(Bubble Sort,台湾另外一种译名为:泡沫排序)是一种简单的排序算法.它重复地走访过要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来.走访数列的工作是重复地进行直到没 ...

  9. HDU 5775 Bubble Sort (线段树)

    Bubble Sort 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5775 Description P is a permutation of t ...

  10. c++算法联系,冒泡排序,bubble sort,插入排序,insert sort,

    #include <iostream.h> #define  MAX 100 void dispaly(int a[],int n) {     for(int i=0;i<n;i+ ...

随机推荐

  1. Idea 使用maven+tomcat的时候,编译指定的Profile

    To build a artifact with a profile you have to create a Maven Run/Debug configuration as in the foll ...

  2. [HDOJ4325]Flowers(树状数组 离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4325 关于离散化的简介:http://blog.csdn.net/gokou_ruri/article ...

  3. PhpStorm+PhpStudy+xdebug 配置图解

    1.配置niginx.ini,新增 server节点,比如使用9200 端口 server { listen 9200;#本地调试,不用80端口 server_name localhost; #cha ...

  4. LBS由ip查经纬度

    LBS API: https://api.map.baidu.com/highacciploc/v1?qcip=223.104.5.201&qterm=pc&ak=NLwCqrDce4 ...

  5. WP7应用版本升级的实现方法

    首先必须要有一个服务提供升级推送查询 // Code to execute when the application is launching (eg, from Start)         //  ...

  6. 函数mem_pool_create

    /********************************************************************//** Creates a memory pool. @re ...

  7. [转载]initwithcoder和 initwithframe

    大前提是UIViewController有一个UIView.同时,需要厘清两个概念,创建一个类和实例化一个类.在XCode中创建一个类和实例化一个类很容易区分,但是在IB(Interface Buil ...

  8. HDU 5375 Gray code 格雷码(水题)

    题意:给一个二进制数(包含3种符号:'0'  '1'  '?'  ,问号可随意 ),要求将其转成格雷码,给一个序列a,若转成的格雷码第i位为1,则得分+a[i].求填充问号使得得分最多. 思路:如果了 ...

  9. 【转】Qt数据库总结

    转自:http://blog.chinaunix.net/uid-25201977-id-3014100.html #include <QtSql>QT += sql QSqlDataba ...

  10. RequireJS进阶(二) 转

    这一篇来认识下打包工具的paths参数,在入门一中就介绍了require.config方法的paths参数.用来配置jquery模块的文件名(jQuery作为AMD模块时id为“jquery”,但文件 ...