-
大小: 2.87KB文件類型: .zip金幣: 1下載: 0 次發布日期: 2021-02-21
- 語言: C/C++
- 標簽:
資源簡介
C++實戰源碼-將若干字符串按照字母順序輸出(入門級實例108).zip
代碼片段和文件信息
//?Order.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include?“stdio.h“
#include?
#include?
void?sort(char?*strings[]?int?n) //對字符串排序
{
????char?*temp;
????int?i?j;
????for?(i?=?0;?i?????{
????????for?(j?=?i?+?1;?j?????????{
????????????if?(strcmp(strings[i]?strings[j])?>?0) //比較字符大小,交換位置
????????????{
????????????????temp?=?strings[i];
????????????????strings[i]?=?strings[j];
????????????????strings[j]?=?temp;
????????????}
????????}
????}
}
int?main()
{
????int?n?=?5;
????int?i;
????char?*strings[]?=
????{
????????“C?language“?“Basic“?“World?wide“?“Hello?world“
????????????“One?worldone?dream!“
????}; //構造字符串數組
????sort(strings?n); //排序
????for?(i?=?0;?i?????????printf(“%s\n“?strings[i]);
????getch();
????return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????927??2010-10-20?09:49??Order\Order.cpp
?????文件????????4524??2010-10-20?09:48??Order\Order.dsp
?????文件?????????535??2010-10-20?09:48??Order\Order.dsw
?????文件?????????292??2010-10-20?09:48??Order\StdAfx.cpp
?????文件?????????769??2010-10-20?09:48??Order\StdAfx.h
- 上一篇:C++實戰源碼-斐波那契數列
- 下一篇:C++實戰源碼-四方定理
評論
共有 條評論