//pointer method, select Sort method for 10 int by small to large arrangement#include <stdio.h>Main () {intn=Ten, i,b,a[Ten],*p; intSortint*q,intN); //scanf ("%d", &10); for(p=a;p<a+Ten;p + +)//keyboard input array elementsscanf"%d", p); P=a;//Super Important!!!!!!!!!! Can't forgetSort (p,Ten);//calling Functions for(p=a;p<a+Ten;p + +)//functions after the output sortprintf"%3d",*p);}intSortint*q,intN) { int*p,i,*j,*k,t; for(k=q;k<q+9; k++) {p=K; for(j=p+1; j<q+Ten; j + +) if(*p>*j) P=J; //*k=*p;t=*K; *k=*p; *p=T; }}
This pointer function is completely self-revision change to complete independently, feel this period of time progress is very big, satisfied!
Remember the idea of sorting, sorting sub-function, reset a pointer variable p, the address of K is assigned to P, is because the address of the J to be assigned to P, and not directly assigned to K, because K is the outside of the loop variable for the loop, can not arbitrarily assign value, will be confused!!
In the main function, before calling the sort function, be sure to reassign p to a (that is, a[0]), because the previous input loop, p already points to the address of a[9].
Pointer selection sorting, 10 integers sorted from small to large