Created
May 12, 2018 01:36
-
-
Save deeshank/81588966dfe40773f6409903b8db9edb to your computer and use it in GitHub Desktop.
Temp
This file contains hidden or 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
ip = [1, 3, 10, 8, 5, 9, 2, 6, 4] | |
ip = [99, 56, 5, 30, 1, 0, 2, 16] | |
n = 5 | |
stop = False | |
sav_idx = -1 | |
cur_idx = 0 | |
while not stop: | |
if cur_idx>=len(ip): | |
break | |
cur = ip[cur_idx] | |
if cur >= n: | |
if cur == n and sav_idx!=-1: | |
ip[cur_idx], ip[sav_idx] = ip[sav_idx], ip[cur_idx] | |
cur_idx = sav_idx | |
sav_idx = -1 | |
if sav_idx >=len(ip): | |
stop = True | |
if sav_idx == -1: | |
sav_idx = cur_idx | |
elif cur < n: | |
if sav_idx!=-1: | |
ip[cur_idx], ip[sav_idx] = ip[sav_idx], ip[cur_idx] | |
cur_idx = sav_idx | |
sav_idx = -1 | |
if sav_idx >=len(ip): | |
stop = True | |
cur_idx+=1 | |
print ip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment