Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Spyder Editor
- This is a temporary script file.
- """
- import sys
- def bidirectional_bubble_sort(a):
- left = -1
- right = len(a)
- while left < right:
- swap = False
- left += 1
- right -= 1
- for i in xrange(left, right):
- if a[i] > a[i + 1]:
- t = a[i]
- a[i] = a[i + 1]
- a[i + 1] = t
- swap = True
- if not swap:
- return
- else:
- swap = False
- for i in xrange(right, left, -1):
- if a[i] < a[i - 1]:
- t = a[i]
- a[i] = a[i - 1]
- a[i - 1] = t
- swap = True
- if not swap:
- return
- def main(argv):
- bidirectional_bubble_sort(argv)
- if __name__ == "__main__":
- main(sys.argv)
Advertisement
Add Comment
Please, Sign In to add comment