[5639] 이진 검색 트리

[5639] 이진 검색 트리

#include < stdio.h >

#include < iostream >

using namespace std ;

int a[ 10001 ], x, cnt;

void f( int start, int end ) {

if (start = = end ) return ;

else if (start = = end - 1 ) {

printf ( "%d

" , a[start]);

return ;

}

int i;

for (i = start + 1 ; i < end & & a[i] < a[start]; i + + );

f(start + 1 , i);

f(i, end );

printf ( "%d

" , a[start]);

}

int main( void ) {

int i = 0 ;

while ( 1 ) {

cin > > x;

if ( cin .eof() = = true ) break ;

a[cnt] = x;

cnt + + ;

}

f( 0 , cnt);

return 0 ;

}

from http://dizlet.tistory.com/54 by ccl(A) rewrite - 2021-09-05 02:00:30