老師上課SHOW的~ 怕有些人懶著抄 ~XD
#include "stdafx.h"
#include <iostream>
#include <string>
#include<iomanip>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
const int arraysize=15;
int data[arraysize]={3, 8, 10, 30, 2, 16, 27, 13, 22, 17, 42, 33, 38, 29, 14};
int flag;
int tmp=0;
for (int i=0;i<=14;i++)
{
cout<<setw(4)<<data[i];
}
cout<<endl;
for (int m=0;m<arraysize-1;m++)
{
flag=0;
for(int l=1;l<=14;l++)
{
if(data[l]>data[l-1])
{
flag=1;
tmp=data[l];
data[l]=data[l-1];
data[l-1]=tmp;
}
}
if (flag==0)
break;
}
for (int i=0;i<=14;i++)
{
cout<<setw(4)<<data[i];
}
cout<<endl;
system("pause");
return 0;
}
P.S. 中間有個"l" 長的很像"1" ~~不要搞混喔!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.240.138