#gcc version 4.5.3 (GCC)

#include <iostream>
#include <algorithm> template <typename ARRAY_TYPE, typename INDEX_TYPE>
void bubble_sort(ARRAY_TYPE array[], INDEX_TYPE size)
{
bool done = false; while(!done)
{
done = true;
for(INDEX_TYPE i = 0; i < size - 1; i++)
{
if(array[i] > array[i+1])
{
done = false;
std::swap(array[i], array[i+1]);
}
}
size--;
}
} template <typename TYPE>
void print(TYPE val)
{
std::cout << val << " ";
} int main()
{
int array[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
bubble_sort(array, 10);
std::for_each(&array[0], &array[10], print<int>);
std::cout << std::endl; int data[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
std::sort(data, data+10);
std::for_each(data, data+10, print<int>);
std::cout << std::endl;
}

  

数据结构-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 ...

随机推荐

  1. PHP的UTF-8中文转拼音处理类(性能已优化至极致)

    <?php /** * PHP 汉字转拼音 * @author Jerryli(hzjerry@gmail.com) * @version V0.20140715 * @package SPFW ...

  2. Java 获取各时区时间,获取当前时间到格林威治时间1970年01月01日00时00分00秒的秒数

    格林威治时间即UTC/GMT时间,1970年01月01日00时00分00秒(即UTC+8的北京时间1970年01月01日08时00分00秒)计算代码如下: /** * 获取指定时间到格林威治时间的秒数 ...

  3. 使用 Velocity 模板引擎快速生成代码(zhuan)

    http://www.ibm.com/developerworks/cn/java/j-lo-velocity1/ ****************************************** ...

  4. IIS_Mvc发布

    网站发布步骤: 这部分是转载文章 在此标明出处,以前有文章是转的没标明的请谅解,因为有些已经无法找到出处,或者与其它原因. 如有冒犯请联系本人,或删除,或标明出处. 因为好的文章,以前只想收藏,但连接 ...

  5. 多语言的sitemap xml

    请注意一下 sitemap xml 也有多语言的

  6. vbox下android分辨率设置

    VBoxManage setextradata "android" "CustomVideoMode1" "1280x800x16" 1.  ...

  7. 用ildasm/ilasm修改IL代码

    原文地址:http://www.cnblogs.com/dudu/archive/2011/05/17/ildasm_ilasm_il.html 在开发中遇到这样一个场景,需要修改一个dll文件(.N ...

  8. VBA对象模型(2)

    Excel对象模型简介 在介绍Excel对象模型之前,让我们先来看一个简单的例子.大多数工厂都是按这样的结构进行设置的:最上层为工厂总部,第二层次分为各个车间,在车间下面又分各班组.就这样组织在一起, ...

  9. Hibernate4+Spring JPA+SpringMVC+Volecity搭建web应用(一)

    pom.xml配置 <dependencies> <!-- hibernate begin --> <dependency> <groupId>org. ...

  10. hdu--(1025)Constructing Roads In JGShining's Kingdom(dp/LIS+二分)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...