冒泡排序
手机敲代码好累啊。程序代码:
#include <stdio.h> #include <time.h> #include <stdlib.h> typedef int E_T; void sort( E_T *array, int l, int r ); int main( void ) { E_T a[ 10 ]; srand( ( unsigned long )time( NULL ) ); for( int i = 0; i < 10; ++i ) { a[ i ] = rand() % 1000; printf( "%d ",a[ i ] ); } printf( "\n" ); sort( a, 0, 10 ); for( int i = 0; i < 10; ++i ) printf( "%d ", a[ i ] ); return 0; } void sort( E_T *array, int l, int r ) { int minix, maxix; int R; for( ; l < r; ++l, --r ) { for( minix = l + 1, maxix = r - 2, R = r - 1; minix <= R; ++minix, --maxix ) { if( array[ l ] > array[ minix ] ) { E_T temp = array[ l ]; array[ l ] = array[ minix ]; array[ minix ] = temp; } if( array[ R ] < array[ maxix ] ) { E_T temp = array[ R ]; array[ R ] = array[ maxix ]; array[ maxix ] = temp; } } } }
[此贴子已经被作者于2017-8-21 11:03编辑过]