例21:冒泡排序

#include<stdio.h>
#include<stdlib.h>

void BubbleSort(int *pArray,int nCount)
{
     for(int i = 0;i<nCount;i++)
     {
             for(int j = 0;j<nCount - i-1;j++)
             {
                     if(pArray[j] > pArray[j+1])
                     {
                                  int tmp = pArray[j];
                                  pArray[j] = pArray[j+1];
                                  pArray[j+1] = tmp;
                     }
             }
     }
}

int main()
{
    int nCount,pArray[20];
    while(~scanf("%d",&nCount) && nCount)
    {
                               for(int i = 0; i<nCount; i++)
                               {
                                       scanf("%d",&pArray[i]);
                               }
                               BubbleSort(pArray,nCount);
                               for(int i = 0;i<nCount;i++)
                               {
                                       printf("%d ",pArray[i]);
                               }
                               printf("
");
    }
    
    return 0;
}
原文地址:https://www.cnblogs.com/FWFC/p/6282493.html