c++冒泡排序
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
#include <iostream.h>
#include <stdio.h>
/*
冒泡排序
paramter:
int* pData:指针数组
int Count:数组大小
return value:返回数组的指针
*/
int *BubbleSort (int* pData,int Count)
{
int iTemp;
for(int i=1;i<Count;i++)
{
for(int j=Count-1;j>=i;j--)
{
if(pData[j]<pData[j-1])
{
iTemp=pData[j-1];
pData[j-1]=pData[j];
pData[j]=iTemp;
}
}
}
return pData;
}
void main()
{
int a[10]={3,2,94,23,34,65,22,33,432,34};
int count=sizeof(a)/sizeof(a[0]);
int *b=BubbleSort(a,count);//定义指针
for(int i=0;i<count;i++)
{
cout<<*(b+i)<<endl;
}
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步