现在的位置: 首页 > 综合 > 正文

C++实现冒泡排序

2018年03月20日 ⁄ 综合 ⁄ 共 393字 ⁄ 字号 评论关闭

#include<iostream>
using namespace std;
template<class T>
void swap(const T &m,const T &n){
T temp;
temp=m;
m=n;
n=temp;
}
int main(int argc,char *argv[]){
int n,i,j;//,*Sort
cin>>n;
//Sort=(int*)malloc(sizeof(int)*n);
int *Sort=new int[n];
for(i=0;i<n;i++){
cin>>Sort[i];
}
for(i=0;i<n-1;i++){
for(j=i+1;j<n;j++){
if(Sort[i]>Sort[j]){
swap(Sort[i],Sort[j]);
}
}
}
for(i=0;i<n;i++){
cout<<Sort[i];
}
//free(Sort);
delete[] Sort;
return 0;
}

抱歉!评论已关闭.