summaryrefslogtreecommitdiff
path: root/progs/a214.py
blob: 5d645c35357d77c0124e0e3cfb292b138d709a89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def sort_by_dnf(arr, n):
  low=0
  mid=0
  high=n-1
  while mid <= high:
    if arr[mid] == 0:
      arr[low], arr[mid] = arr[mid], arr[low]
      low = low + 1
      mid = mid + 1
    elif arr[mid] == 1:
      mid = mid + 1
    else:
      arr[mid], arr[high] = arr[high], arr[mid]
      high = high - 1
  return arr