#include<stdio.h>//頭文件?
int main()//主函數(shù)?
{
? void sort(int **point,int number); //sort排序函數(shù)聲明?
? int i,number,data[20],**point,*pstr[20]; //定義變量?
? scanf("%d",&number);//鍵盤輸入?
? for(i=0;i<number;i++)
{
? ? pstr[i]=&data[i]; //將第i個(gè)整數(shù)的地址賦予指針數(shù)組pstr的第i個(gè)元素?
? }
? for(i=0;i<number;i++)
? {
? ? scanf("%d",pstr[i]);//挨個(gè)輸入要排序的數(shù)?
? }
point=pstr;
? sort(point,number);?
? for(i=0;i<number;i++)
? {
? ? printf("%d ",*pstr[i]);//輸出排序后的結(jié)果?
? }
? printf("\n");//換行?
return 0;//主函數(shù)返回值為0?
}
void sort(int **point,int number)//自定義sort排序函數(shù)?
{
? int i,j,*temp;//定義變量?
? for(i=0;i<number-1;i++)
? {
for(j=i+1;j<number;j++)
? ? {
? ? ? if(**(point+i)>**(point+j))//比較之后交換整數(shù)地址?
? ? ? {?
? ? ? ? temp=*(point+i);
? ? ? ? *(point+i)=*(point+j);
? ? ? ? *(point+j)=temp;文章來源:http://www.zghlxwxcb.cn/news/detail-765968.html
}
? ? }
? }
}
?文章來源地址http://www.zghlxwxcb.cn/news/detail-765968.html
到了這里,關(guān)于練習(xí)-用指針方法將n個(gè)整數(shù)按升序排列(選擇排序)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!