24 lines
566 B
Python
Executable file
24 lines
566 B
Python
Executable file
#!/usr/bin/env python3
|
|
# vim: set ts=4 sw=4 et tw=80:
|
|
|
|
import sys
|
|
|
|
# This is a modified version of BubbleSort that swaps elements only if the first
|
|
# is odd and the second one is even
|
|
def partition_even_odd(x):
|
|
i = len(x) - 1
|
|
while i > 0:
|
|
for j in range(0, i):
|
|
if x[j] % 2 == 1 and x[j+1] % 2 == 0:
|
|
c = x[j]
|
|
x[j] = x[j+1]
|
|
x[j+1] = c
|
|
i = i - 1
|
|
|
|
def main():
|
|
args = [int(x) for x in sys.argv[1:]]
|
|
partition_even_odd(args)
|
|
print(args)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|