I l@ve RuBoard Previous Section Next Section

inplace_merge()

inplace_merge() takes three iterator parameters: first, middle, and last. Two input sequences are marked by [first,middle] and [middle,last] (middle marks 1 past the last element of the first sequence). These sequences must be consecutive. The resulting sequence overwrites the two ranges beginning at first. An optional fourth parameter allows us to specify an ordering operation other than the default less-than operator.



#include <algorithm> 


int ia[20] = { 29,23,20,17,15,26,51,12,35,40, 


               74,16,54,21,44,62,10,41,65,71 }; 





int *middle = ia+10, *last = ia+20; 





// 12 15 17 20 23 26 29 35 40 51 10 16 21 41 44 54 62 65 71 74 


sort( ia, middle ); sort( middle, last ); 





// 10 12 15 16 17 20 21 23 26 29 35 40 41 44 51 54 62 65 71 74 


inplace_merge( ia, middle, last ); 
    I l@ve RuBoard Previous Section Next Section