使用指针实现对数组元素由小到大的排序
#include <stdio.h>
#define len 10
void plArrary(int pArrary[],int length)
{
for (int i=0; i<=length-1; i++) {
for (int j=i+1; j<length; j++) {
if (*(pArrary+i)>*(pArrary+j)) {
int t=*(pArrary+i);
*(pArrary+i)=*(pArrary+j);
*(pArrary+j)=t;
}
}
}
}
void printArray(int *pArrary,int length)
{
for (int i=0; i<length; i++) {
printf(" %d",*pArrary);
pArrary++;
}
}
int main(int argc, const char * argv[]) {
int stu[len]={82,67,79,93,45,77,100,23,43,87};
int *p;
p=stu;
plArrary(stu, len);
printf("由小到大排列:\n");
printArray(stu, len);
return 0;
}