什么是折半排序法?
输入10个数,逆序输出(折半)。求详解,百度上都是折半查找法
#include < stdio.h > #include < stdlib.h > #define N 15 void main ( ) { int i, number, top, bott, mid, loca, a[N], flag = 1, sign; char c; printf ( "enter data:\n" ); scanf ( "%d", &a[0] ); i = 1; while ( i < N ) { scanf ( "%d", &a[i] ); if ( a[i] >= a[i - 1]) i++; else printf ( "enter this data again:\n" ); } printf ( "\n" ); for ( i = 0;i < N; i++ ) printf ( "%d", a[i] ); printf ( "\n" ); while ( flag ) { printf ( "input number to look for : "); scanf ( "%d", &number ); sign = 0; top = 0; bott = N - 1; if ( ( number < a[0]) || ( number > a[N-1]) ) loca = -1; while ( ( !sign ) && ( top <= bott ) ) { mid = ( bott + top )/2; if ( number == a[mid] ) { loca = mid; printf ( "Has found %d ,its position is %d\n", number, loca + 1 ); sign = 1; } else if ( number < a[mid] ) bott = mid -1; else top = mid + 1; } if ( !sign ||loca == -1 ) printf ( "can not find %d.\n",number ); printf ( "continue or not ( Y/N )?" ); scanf ( "%c",&c ); if ( c == 'N' || c == 'n' ) flag = 0; } system ( "pause" ); }这是个找到一个和已知数组相同的程序,用的正是,折半排序法,前两天写的一个程序,给你看看