View Code
View Code View Code
: j++; ; : i--; ; :
: i--; ; : j++; ; :
Ascending = a[] > a[] ? : ;
memset(CopyA, , () * len);
(order == -- ++begin;
(order == ++ --end;
(a[] < a[len - = =
order = ;
(a[] > a[len - =
order = a[] > a[len - ];
(order == (begin <(a[begin] + a[end] >-- (a[begin] + a[end] == ++(begin <(a[begin] + a[end] >++ (a[begin] + a[end] == --
#include <stdio.h> #include <stdbool.h> #define X 31 bool judge(int [], size_t , int ); int main( void ) { int test[]= { 5,10,21,41,59 } ;//{ 59,41,21,10,5 }; printf ( "%d%s存在!\n", X , judge( test , sizeof test/sizeof *test, X ) ? "" :"不" ); return 0; } bool judge( int a[] , size_t n , int x ) { if ( n < 2u ) return false; if ( x == a[0] + a[n-1] ) return true; if ( (x > a[0] + a[n-1]) ^ ( a[0] > a[n-1]) ) return judge( a + 1, n - 1 , x ) ; return judge( a , n - 1 , x ); }
bool judge( int a[] , size_t n , int x ) { while ( n > 1u ) { if ( x == a[0] + a[n-1] ) return true ; if ( (x > a[0] + a[n-1]) ^ ( a[0] > a[n-1]) ) a ++ ; n -- ; } return false ; }