C++98冒泡排序代碼
#include <iostream>
using namespace std;
int n, a[100];
int main()
{
? ? cin >> n;
? ? for (int i = 1; i <= n; i++)
? ? {
? ? ? ? cin >> a[i];
? ? }
? ? for(int i=1;i<=n-1;i++)
? ? {
? ? ? ? for(int j=i+1;j<=n;j++)
? ? ? ? {
? ? ? ? ? ? if(a[i]<a[j])
? ? ? ? ? ? {
? ? ? ? ? ? ? ? int k=a[i];
? ? ? ? ? ? ? ? a[i]=a[j];
? ? ? ? ? ? ? ? a[j]=k;
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? for (int i = 1; i <= n; i++)
? ? {
? ? ? ? if(a[i]!=a[i-1])
? ? ? ? {
? ? ? ? ? ?cout<<a[i]<<" ";
? ? ? ? }
? ? }
? ? return 0;
}
標(biāo)簽: