Guest User

Untitled

a guest
Nov 21st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. namespace ArrayNumbers
  2. {
  3. using FluentAssert;
  4. using Microsoft.VisualStudio.TestTools.UnitTesting;
  5.  
  6. [TestClass]
  7. public class SplitArrayByX
  8. {
  9. [TestMethod]
  10. public void X_Povided_ShouldSplitArray()
  11. {
  12. var test = new[]
  13. {
  14. 1, 4, 3, 7, 9, -1
  15. };
  16. var sorted = SortByX(test.Clone() as int[], 5);
  17. sorted.ShouldBeEqualTo(new[] {1, 4, 3, -1, 9, 7});
  18.  
  19. test = new[]
  20. {
  21. 4, 2, 7, 1, 6, 3, 0, 8
  22. };
  23.  
  24. sorted = SortByX(test.Clone() as int[], 6);
  25. sorted.ShouldBeEqualTo(new[] {4, 2, 0, 1, 3, 6, 7, 8});
  26. }
  27.  
  28. private int[] SortByX(int[] a, int x)
  29. {
  30. for (int i = 0; i < a.Length; i++)
  31. {
  32. if (a[i] >= x)
  33. {
  34. for (int j = a.Length - 1; j > i; j--)
  35. {
  36. if (a[j] < x)
  37. {
  38. var temp = a[i];
  39. a[i] = a[j];
  40. a[j] = temp;
  41. }
  42. }
  43. }
  44. }
  45. return a;
  46. }
  47. }
  48. }
Add Comment
Please, Sign In to add comment