[轉錄][轉錄][C++] 上機考 (9)
※ [本文轉錄自 NTUBIME99-HW 看板]
作者: matrixjimmy (Jimmy) 看板: NTUBIME99-HW
標題: [轉錄][C++] 上機考 (9)
時間: Sun Dec 17 14:50:16 2006
※ [本文轉錄自 NTUBIME97-HW 看板]
作者: ychia (12/13~17 生機週!!) 看板: NTUBIME97-HW
標題: [C++] 上機考 (9)
時間: Wed Dec 8 00:25:52 2004
#include <iostream>
using std::cout;
using std::endl;
int bublesort( int [], const int );
int main()
{
const unsigned int arraySize = 15;
int a[] = {3, 8, 10, 30, 2, 16, 27, 13, 22, 17, 42, 33, 38, 29, 14};
bublesort( a, arraySize);
for ( int i = 0; i < arraySize; i++ )
cout << "a[" << i << "] = " << a[i] << endl;
return 0;
}
int bublesort( int a[], const int size ) // 由小到大排列
{
int temp;
for ( int i = 0; i < size - 1; i++ )
for ( int j = 0; j < size - 1; j++ )
if ( a[ j ] > a[ j + 1 ] ) {
temp = a[ j ];
a[ j ] = a[ j + 1 ];
a[ j + 1 ] = temp;
}
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.22.100
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.62.101.203
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.241.52