Created
October 10, 2016 19:36
-
-
Save kharioki/0985b3f82b46cf3d506c5eefc6d4558b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sort_mylist_asc(a): | |
for my_number in range(len(a)-1,0,-1): | |
for i in range(my_number): | |
if a[i]>a[i+1]: | |
temp = a[i] | |
a[i] = a[i+1] | |
a[i+1] = temp | |
return a | |
def sort_mylist_desc(a): | |
for desc in range(len(a)-1,0,-1): | |
for i in range(desc): | |
if a[i]<a[i+1]: | |
des = a[i+1] | |
a[i+1] = a[i] | |
a[i] = des | |
return a | |
def re_arrange(a): | |
arr_re = [] | |
# sort the array | |
arr = sort_mylist_asc(a) | |
# slice the array into two | |
arr_first = arr[0:int((len(arr)+1)/2)] | |
arr_second = arr[int((len(arr)+1)/2):] | |
# PUt the first half into the rearraged array | |
arr_second = sort_mylist_desc(arr_second) | |
# Take the second half | |
arr_re = arr_first + arr_second | |
return arr_re | |
# the latest result to the rearranged array | |
a = [54,26,93,17,77,31,44,44,55,20,-76,-56] | |
print(re_arrange(a)) | |
print(re_arrange(a[1:-1])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment