【求助】冒泡排序-指针
我想用函数调用的方式进行冒泡排序,用指针变量做实参和形参...但是错了很多...求高手帮帮
程序代码:/* 2.使用指针作形参,指针为实参*/
#include<stdio.h>
int main()
{
void sort(int *p,int n);
int i,a[15],n,*p;
p=a;
printf("Please input the array's number:");
scanf("%d",&n);
printf("Please inpur the array's data:");
for(i=0;i<n;i++)
scanf("%d",p++);
p=a;
printf("The origin array is:");
for(i=0;i<n;i++)
printf("%5d",*p++);
printf("\n");
p=a;
sort(p,n);
p=a;
for(i=0;i<n;i++)
printf("%5d",*p++);
printf("\n");
return 0;
}
void sort(int *p,int n)
{
int i,j,*q,*t,temp;
for(i=0;i<n-1;i++)
for(j=0;i+j<n-1;j++,p++){
q=p+1;
if(*p>*q){
temp=*p;
*p=*q;
*q=temp;
t=q;
}
else t=p;
}
}







