





import operator


def 	UpperCamelCase__(       UpperCamelCase__			:       list ,     UpperCamelCase__			:       bool = False ,     UpperCamelCase__			:       list | None = None  )->Dict:
       A__											=						operator.lt if reverse else operator.gt
       A__											=						solution or []

       if not arr:
              return solution

       A__											=						[arr.pop(0  )]
       for i, item in enumerate(_lowerCamelCase  ):
              if _operator(_lowerCamelCase ,     sublist[-1]  ):
                     sublist.append(_lowerCamelCase  )
                     arr.pop(_lowerCamelCase  )

    #  merging sublist into solution list
       if not solution:
              solution.extend(_lowerCamelCase  )
       else:
              while sublist:
                     A__											=						sublist.pop(0  )
                     for i, xx in enumerate(_lowerCamelCase  ):
                            if not _operator(_lowerCamelCase ,     _lowerCamelCase  ):
                                   solution.insert(_lowerCamelCase ,     _lowerCamelCase  )
                                   break
                     else:
                            solution.append(_lowerCamelCase  )

       strand_sort(_lowerCamelCase ,     _lowerCamelCase ,     _lowerCamelCase  )
       return solution


if __name__ == "__main__":
       assert strand_sort([4, 3, 5, 1, 2]) == [1, 2, 3, 4, 5]
       assert strand_sort([4, 3, 5, 1, 2], reverse=True) == [5, 4, 3, 2, 1]






import operator

def 			lowercase_				(			_lowerCamelCase							:       list		,	_lowerCamelCase							:       bool = False		,	_lowerCamelCase							:       list | None = None):
    lowercase__ :   int    					=				operator.lt if reverse else operator.gt
    lowercase__ :   str    					=				solution or []

    if not arr:
        return solution

    lowercase__ :   List[str]    					=				[arr.pop(0)]
    for i, item in enumerate(_lowerCamelCase):
        if _operator(_lowerCamelCase		,	sublist[-1]):
            sublist.append(_lowerCamelCase)
            arr.pop(_lowerCamelCase)

    #  merging sublist into solution list
    if not solution:
        solution.extend(_lowerCamelCase)
    else:
        while sublist:
            lowercase__ :   str    					=				sublist.pop(0)
            for i, xx in enumerate(_lowerCamelCase):
                if not _operator(_lowerCamelCase		,	_lowerCamelCase):
                    solution.insert(_lowerCamelCase		,	_lowerCamelCase)
                    break
            else:
                solution.append(_lowerCamelCase)

    strand_sort(_lowerCamelCase		,	_lowerCamelCase		,	_lowerCamelCase)
    return solution


if __name__ == "__main__":
      assert strand_sort([4, 3, 5, 1, 2]) == [1, 2, 3, 4, 5]
      assert strand_sort([4, 3, 5, 1, 2], reverse=True) == [5, 4, 3, 2, 1]



