資源簡介
C++實戰源碼-使用函數模板進行排序(入門級實例189).zip
代碼片段和文件信息
//?Sort.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include?“ioStream.h“
template? //定義一個模板
void?Sort(Type?Array[]?int?nLen)
{
for(int?i=0;?i {
for(int?j=0;?j {
if?(Array[j]?>?Array[j+1]) //交換數組元素
{
Type?nTmp?=?Array[j];
Array[j]?=?Array[j+1];
Array[j+1]?=?nTmp;
}
}
}
}
int?main(int?argc?char*?argv[])
{
int?nArray[]?=?{85?98?45?76?75}; //定義一個整型數組
Sort(nArray?5); //對數組進行排序
cout?<“整數排序“?< for(int?i=0;?i<5;?i++) //輸出結果
{
cout?< }
double?dArray[]?=?{76.85?95.75?84.56?85.5?67.4}; //定義實數數組
Sort(dArray?5); //對數組進行排序
cout?<“實數排序“?< for(int?j=0;?j<5;?j++) //輸出結果
{
cout?< }
return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????958??2010-10-14?19:58??Sort\Sort.cpp
?????文件????????4512??2010-10-14?19:54??Sort\Sort.dsp
?????文件?????????533??2010-10-14?19:54??Sort\Sort.dsw
?????文件?????????291??2010-10-14?19:54??Sort\StdAfx.cpp
?????文件?????????769??2010-10-14?19:54??Sort\StdAfx.h
- 上一篇:C++實戰源碼-哥德巴赫猜想
- 下一篇:C++實戰源碼-集郵冊中的郵票數量
評論
共有 條評論