基本排序算法--冒泡排序
2015-08-25 20:36
274 查看
#include<iostream> using namespace std; void BubbleSort(int a[], int n) { for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { if (a[j]>a[j + 1]) { int temp = a[j]; a[j] = a[j + 1]; a[j + 1] = temp; } } } } int main() { int array[] = { 34, 65, 12, 43, 67, 5, 78, 10, 3, 70 }; int len = sizeof(array) / sizeof(int); cout << "the original array are:" << endl; for (int k = 0; k < len; k++) cout << array[k] << " "; cout << endl; BubbleSort(array, len); cout << "The sorted array are:" << endl; for (int k = 0; k<len; k++) cout << array[k] << ","; cout << endl; return 0; }
相关文章推荐
- AES分组对称加密算法学习笔记
- IOS学习之iOS开发UI基础—手写控件,frame,center和bounds属性
- JAVA基础9(设计模式 单例模式 工厂模式 建造者模式 原型模式)
- POJ 1466 && ZOJ 1137--Girls and Boys【二分图 && 最大点独立集】
- 黑马程序员-OC-类方法和对象方法的调用
- 阿里巴巴常考面试题及汇总答案
- 树的共同祖先
- program files与program files(x86)的区别
- Android UI设计——ListView控件和自定义Adapter(四)
- hdoj找新朋友
- 剑指offer面试题java实现之题6:重建二叉树
- iOS 宏(define)与常量(const)的正确使用
- 【读书笔记】iOS-读取文本文件
- ConcurrentHashMap源码-转载
- fedora22安装多媒体插件
- Neo4j图数据库介绍
- HDU3631(Shortest Path)
- 九度oj 1140
- Python os.path 模块介绍
- iOS中Block介绍(一)基础