Advertisement
osteth

Tuple-PyramidSort.py

Apr 19th, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. def main():
  2.     inputArray = [(1, 2), (2, 3), (1, 5), (5, 3), ( 4, 1), (1, 2), (5, 5), (3, 4)]
  3.  
  4.     print psort(inputArray)
  5.  
  6.     raw_input('Press <ENTER> to continue')
  7.  
  8.  
  9.  
  10. def psort(array):
  11.  
  12.     array.sort()
  13.     n = 0
  14.     pyrArray = []
  15.     index = 0
  16.  
  17.     while len(array) > 0:
  18.         if n == 0:
  19.             pyrArray.insert(index, array.pop(0))
  20.             index += 1
  21.             n = 1
  22.         else:
  23.             pyrArray.insert(len(pyrArray) - index, array.pop(0))
  24.             n = 0
  25.  
  26.     pyrArray.reverse()
  27.  
  28.     return pyrArray
  29.  
  30.  
  31. if __name__ == "__main__":
  32.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement