JoshRagem
0
Q:

Move all the negative elements to one side of the array


 
def rearrange(arr, n ) :
 
    j = 0
    for i in range(0, n) :
        if (arr[i] < 0) :
            temp = arr[i]
            arr[i] = arr[j]
            arr[j]= temp
            j = j + 1
    print(arr)
 
arr = [-1, 2, -3, 4, 5, 6, -7, 8, 9]
n = len(arr)
rearrange(arr, n)
 
0

New to Communities?

Join the community