Sort the Array by reversing the numbers in it | Function to return the reverse of n ; Function to sort the array according to the reverse of elements ; Vector to store the reverse with respective elements ; Inserting reverse with elements in the vector pair ; Sort the vector , this will sort the pair according to the reverse of elements ; Print the sorted vector content ; Driver code
def reversDigits ( num ) : NEW_LINE INDENT rev_num = 0 ; NEW_LINE while ( num > 0 ) : NEW_LINE INDENT rev_num = rev_num * 10 + num % 10 ; NEW_LINE num = num // 10 ; NEW_LINE DEDENT return rev_num ; NEW_LINE DEDENT def sortArr ( arr , n ) : NEW_LINE INDENT vp = [ ] ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT vp . append ( ( reversDigits ( arr [ i ] ) , arr [ i ] ) ) ; NEW_LINE DEDENT vp . sort ( ) NEW_LINE for i in range ( len ( vp ) ) : NEW_LINE INDENT print ( vp [ i ] [ 1 ] , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 12 , 10 , 102 , 31 , 15 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE sortArr ( arr , n ) ; NEW_LINE DEDENT