Answers for "Move all the negative elements to one side of the array"

1

Move all the negative elements to one side of the array

def rearrange(arr):
    low = 0
    high = 0
    while high<len(arr):
        if (arr[high] < 0):
            arr[high], arr[low] = arr[low] , arr[high]
            low += 1
        high += 1 
    print(arr)
              
# Driver code
arr = [-1, 2, -3, 4, 5, 6, -7, 8, 9]
rearrange(arr)
#Output -> [-1, -3, -7, 4, 5, 6, 2, 8, 9]
Posted by: Guest on September-10-2021

Code answers related to "Move all the negative elements to one side of the array"

Python Answers by Framework

Browse Popular Code Answers by Language