Created
June 8, 2015 05:47
-
-
Save psaitu/908e9b5bfaf9c261939c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = [79, 50, 68, 71, 73, 31, 81, 30, 33, 94, 60, 63, 99, 81, 99, 96, 59, 73, 13] | |
| n = len(a) | |
| def is_even(n): | |
| return (n % 2 == 0) | |
| def is_odd(n): | |
| return (n % 2 != 0) | |
| def check_mismatch_even(i, n): | |
| if(is_even(i) and is_odd(n)): | |
| return True | |
| else: | |
| return False | |
| def check_mismatch_odd(j, n): | |
| if(is_odd(j) and is_even(n)): | |
| return True | |
| else: | |
| return False | |
| def swap(i, j): | |
| temp = a[i] | |
| a[i] = a[j] | |
| a[j] = temp | |
| i = 0 | |
| while(i<n): | |
| if (check_mismatch_even(i, a[i])): | |
| j = i + 1 | |
| while ( j < n ): | |
| if( check_mismatch_odd(j, a[j]) ): | |
| swap(i, j) | |
| break | |
| j += 1 | |
| if( check_mismatch_odd(i, a[i]) ): | |
| j = i + 1 | |
| while( j < n ): | |
| if( check_mismatch_even(j, a[j]) ): | |
| swap(i, j) | |
| break | |
| j += 1 | |
| i += 1 | |
| print a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment