[C++ ] 排序

看板NTUBIME100HW作者 (Magic)時間18年前 (2007/12/06 23:52), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
老師上課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
文章代碼(AID): #17M1gbWu (NTUBIME100HW)