首页 > 学院 > 开发设计 > 正文

冒泡排序

2019-11-11 03:57:50
字体:
来源:转载
供稿:网友
#include <iostream>using namespace std;void bubble_sort(int unsorted[],int length){for (int i = 0; i < length; i++){for (int j = i; j < length; j++){if (unsorted[i] > unsorted[j]){int temp = unsorted[i];unsorted[i] = unsorted[j];unsorted[j] = temp;}}}} void main(){int x[] = { 6, 2, 4, 1, 5, 9 };bubble_sort(x,sizeof(x)/sizeof(x[0]));for(int item : x){cout<<(item);}cout << endl;system("pause");}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表