fork(1) download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. static void Main(string[] args)
  6. {
  7. int[] newInt = new int[] { 5, -2, -1, -4, -20, 6, 7, -14, 15, -16, 8, 9, 10 };
  8. int size = 12, i= 0; // or newInt.Length
  9.  
  10. int left = 0, right = newInt.Length-1;
  11. while (left < right) {
  12. if (newInt[left] < 0 && newInt[right] > 0) {
  13. int temp = newInt[left];
  14. newInt[left] = newInt[right];
  15. newInt[right] = temp;
  16. right--;
  17. left++;
  18. continue;
  19. }
  20. if (newInt[left] > 0) {
  21. left++;
  22. }
  23. if (newInt[right] < 0) {
  24. right--;
  25. }
  26. }
  27. for (i = 0; i < newInt.Length; i++)
  28. {
  29. Console.Write(newInt[i]);
  30. Console.Write(" ");
  31.  
  32. }
  33.  
  34. }
  35. }
Success #stdin #stdout 0.03s 33920KB
stdin
Standard input is empty
stdout
5 10 9 8 15 6 7 -14 -20 -16 -4 -1 -2