排序_Bubble_sort(冒泡排序)
2012-11-09 16:25
561 查看
冒泡排序,时间复杂度是O(n^2),但是它的有点也十分优越,那就是比较容易敲出来代码,而且相对稳定,是一种稳定的排序方法.
贴出代码:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string>
#define inf 0x3fffffff
using namespace std;
int N;
int a[1000];
void Bubble_sort ()
{
for (int i = 1 ; i < N ; i++)
{
for (int j = 0; j < N - 1; j++)
{
if (a[j] > a[j + 1])
{
int t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
}
}
}
}
int main()
{
cout << "Input the number that you want be sorted : " << endl;
cin >> N;
cout << "Input the numbers :" << endl;
for (int i = 0; i < N ; i++)
{
cin >> a[i];
}
Bubble_sort ();
for (int i = 0; i < N; i++)
{
cout << a[i] << " ";
}
cout << endl;
system ("pause");
return 0;
}
贴出代码:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string>
#define inf 0x3fffffff
using namespace std;
int N;
int a[1000];
void Bubble_sort ()
{
for (int i = 1 ; i < N ; i++)
{
for (int j = 0; j < N - 1; j++)
{
if (a[j] > a[j + 1])
{
int t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
}
}
}
}
int main()
{
cout << "Input the number that you want be sorted : " << endl;
cin >> N;
cout << "Input the numbers :" << endl;
for (int i = 0; i < N ; i++)
{
cin >> a[i];
}
Bubble_sort ();
for (int i = 0; i < N; i++)
{
cout << a[i] << " ";
}
cout << endl;
system ("pause");
return 0;
}
相关文章推荐
- 自己实现一个bubble_sort(冒泡排序),可以完成不同类型数据的排序
- 一天一排序之“冒泡排序(Bubble_sort)”
- 自己完成一个冒泡排序(bubble_sort),可以完成不同类型数据的排序
- 冒泡排序(Bubble_Sort)
- java中的三种排序方法使用:选择排序,冒泡排序,sort方法排序。
- 2014.2.25 改进型冒泡排序 improved bubble sort algorithm
- 字符串排序... toBubbleSort...strcmp(arr[j], arr[j + 1]) > 0...c语言 条件 -1 也能打印 囧
- JS排序方法(sort,bubble,select,insert)代码汇总
- 冒泡排序(bubble sort)、直接插入排序(straight insertion sort)、简单选择排序(simple selection sort)
- Recursive Bubble Sort(递归冒泡排序)
- Aizu ALDS1_2_A Bubble Sort(冒泡排序)
- 冒泡排序(Bubble_Sort)
- 冒泡排序的改进(Modified_Bubble_Sort)
- 冒泡排序(bubble_sort)详解
- Java BubbleSort(冒泡排序)
- js 排序:sort()方法、冒泡排序、二分法排序。
- 冒泡排序(bubbleSort.cpp)
- 冒泡排序 Bubble Sort Aizu - ALDS1_2_A
- 冒泡排序和快速排序以及Android的collections.sort排序
- AOJ-ALDS1_2_A Bubble Sort【冒泡排序】