This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
DSA/partition_even_odd.py

25 lines
566 B
Python
Raw Normal View History

2019-02-20 12:58:39 +00:00
#!/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()