Add elements in start to sort the array | Variation of Stalin Sort | Function to sort the array ; Iterator < Integer > index = arr . iterator ( ) ; ; Driver Code ; Function Call
def variationStalinsort ( arr ) : NEW_LINE INDENT j = 0 NEW_LINE while True : NEW_LINE INDENT moved = 0 NEW_LINE for i in range ( len ( arr ) - 1 - j ) : NEW_LINE INDENT if arr [ i ] > arr [ i + 1 ] : NEW_LINE INDENT arr . insert ( moved , arr . pop ( i + 1 ) ) NEW_LINE moved += 1 NEW_LINE DEDENT DEDENT j += 1 NEW_LINE if moved == 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT return arr NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 2 , 1 , 4 , 3 , 6 , 5 , 8 , 7 , 10 , 9 ] NEW_LINE print ( variationStalinsort ( arr ) ) NEW_LINE DEDENT