Advertisement
1sairandhri

move_negatives_to_front

Apr 9th, 2020
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.25 KB | None | 0 0
  1. arr = [-12, 11, -13, -5, 6, -7, 5, -3, -6]
  2. for i in range(len(arr)):
  3.     key = arr[i]
  4.     if (key  > 0):
  5.         continue
  6.     j = i - 1
  7.     while (j >= 0 and arr[j] > 0):
  8.         arr[j + 1] = arr[j]
  9.         j = j - 1
  10.     arr[j + 1] = key
  11. arr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement