Pop elements from stack while stack is not empty and top of stack is smaller than arr [ i ] . We always have elements in decreasing order in a stack .
while ( s . empty ( ) == false && s . top ( ) < arr [ i ] ) s . pop ( ) ;