fork(4) 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.  
  11. for (i = 0; i < size ; )
  12. {
  13.  
  14. if (newInt[i] < 0 && newInt[size] > 0) {
  15. int temp = newInt[i];
  16. newInt[i] = newInt[size];
  17. newInt[size] = temp;
  18. size--;
  19. i++;
  20. continue;
  21. }
  22. if (newInt[i] > 0) {
  23. i++;
  24. }
  25. if (newInt[size] < 0) {
  26. size--;
  27. }
  28. }
  29. for (i = 0; i < newInt.Length; i++)
  30. {
  31. Console.Write(newInt[i]);
  32. Console.Write(" ");
  33.  
  34. }
  35.  
  36. }
  37. }
Success #stdin #stdout 0.03s 33856KB
stdin
Standard input is empty
stdout
5 10 9 8 15 6 7 -14 -20 -16 -4 -1 -2