daily pastebin goal
32%
SHARE
TWEET

Tuple-PyramidSort.py

osteth Apr 19th, 2016 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top