資源簡介
C++實戰源碼-使用指針實現整數排序(入門級實例101).zip
代碼片段和文件信息
//?Compositor.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include?“iostream.h“
#include?
void?swap(int?*p1?int?*p2)
{
????int?temp; //聲明整型變量
????//交換兩個指針指向的值
????temp?=??*p1;
????*p1?=??*p2;
????*p2?=?temp;
}
void?exchange(int?*pt1?int?*pt2?int?*pt3) //比較數值大小并進行交換
{
//從大到小順序排列
if?(*pt1??*pt2)
swap(pt1?pt2);
if?(*pt1??*pt3)
swap(pt1?pt3);
if?(*pt2??*pt3)
swap(pt2?pt3);
}
int?main()
{
int?a?b?c??*q1??*q2??*q3; //聲明變量
puts(“請輸入3個數:“);
scanf(“%d%d%d“?&a?&b?&c); //輸入3個數
q1?=?&a;
q2?=?&b;
q3?=?&c;
exchange(q1?q2?q3); //比較大小交換位置
printf(“\n%d%d%d\n“?a?b?c); //輸出交換后的值
return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????808??2010-11-12?13:05??Compositor\Compositor.cpp
?????文件????????4584??2010-10-20?09:07??Compositor\Compositor.dsp
?????文件?????????545??2010-10-20?09:07??Compositor\Compositor.dsw
?????文件?????????297??2010-10-20?09:07??Compositor\StdAfx.cpp
?????文件?????????769??2010-10-20?09:07??Compositor\StdAfx.h
- 上一篇:C++實戰源碼-計算幾何圖形的面積
- 下一篇:C++實戰源碼-模板的實現
評論
共有 條評論