简单的指针运用程序,帮忙查查
程序代码:
#include<stdio.h> #define SIZE 10 void bubbleSort( int *const sPtr, const int SIZE ); int mian() { int s[SIZE] = { 2, 4, 6, 8, 10, 33, 1 }; for( int i = 0; i < SIZE; i++ ){ printf( "%d ", s[i] ); } bubbleSort( s, SIZE ); for( int i = 0; i < SIZE; i++ ){ printf( "%d ", s[i] ); } printf( "\n" ); return 0; } void bubbleSort( int *const sPtr, const int SIZE ) { void swap( int *a, int *b ); int i; int j; for( i = 1; i < SIZE; i++ ){ for( j = 0; j < SIZE - i; j++ ){ if( sPtr[j] > sPtr[j + 1] ) swap( sPtr[j], sPtr[j + 1] ); }//end inner for }//end for } void swap( int *a, int *b ) { int c; c = *a; *a = *b; *b = c; }