Sort 1 to N by swapping adjacent elements | Return true if array can be sorted otherwise false ; Check if array is sorted or not ; Driver program
def sortedAfterSwap ( A , B , n ) : NEW_LINE INDENT for i in range ( 0 , n - 1 ) : NEW_LINE INDENT if B [ i ] : NEW_LINE INDENT if A [ i ] != i + 1 : NEW_LINE INDENT A [ i ] , A [ i + 1 ] = A [ i + 1 ] , A [ i ] NEW_LINE DEDENT DEDENT DEDENT for i in range ( n ) : NEW_LINE INDENT if A [ i ] != i + 1 : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT A = [ 1 , 2 , 5 , 3 , 4 , 6 ] NEW_LINE B = [ 0 , 1 , 1 , 1 , 0 ] NEW_LINE n = len ( A ) NEW_LINE if ( sortedAfterSwap ( A , B , n ) ) : NEW_LINE INDENT print ( " A ▁ can ▁ be ▁ sorted " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " A ▁ can ▁ not ▁ be ▁ sorted " ) NEW_LINE DEDENT DEDENT