Move all the negative elements to one side of the array in C#
Solution 1:
Output
-7 -3 -1 2 4 5 6 8 9
Solution 1:
/ C# program to move all negative numbers to the
// beginning and all positive numbers to the end with
// constant extra space
using System;
using System.Collections;
public class Gfg {
public static void Main()
{
int[] arr = { -1, 2, -3, 4, 5, 6, -7, 8, 9 };
Array.Sort(arr);
foreach (int e in arr)
Console.Write(e + " ");
}
}
// This code is contributed by Saurabh Jaiswal
-7 -3 -1 2 4 5 6 8 9
Comments
Post a Comment