1. Merge Sort (Recursion)
void merge(int bb, int mm, int ee){ int b = bb, k = bb, m = mm+1; while( b <= mm && m <= ee ) { if( A[ b ] <= A[ m ] ) S[ k++ ] = A[ b++ ]; else S[ k++ ] = A[ m++ ]; } if( b <= mm ) while( b <= mm ) S[ k++ ] = A[ b++ ]; else while( m <= ee ) S[ k++ ] = A[ m++ ]; for( int i = bb; i <= ee; i++) A[ i ] = S[ i ]; } void merge_sort(int bb, int ee){ if( bb < ee ) { int mm = (bb + ee) / 2; merge_sort( bb, mm ); merge_sort( mm+1, ee ); merge( bb, mm, ee ); } }
댓글 없음:
댓글 쓰기