Advertisement
Guest User

C# BubbleSort Algorithm Example

a guest
May 26th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. using System;
  2.  
  3. namespace BubbleSort
  4. {
  5. class Program
  6. {
  7. public static void Main()
  8. {
  9. int[] odd = new int[6] { 99, 97, 95, 87, 77, 93 };
  10.  
  11. bool swapped = true;
  12.  
  13. while (swapped == true)
  14. {
  15. swapped = false;
  16.  
  17. for (int y = 0; y < odd.Length - 1; y++)
  18. {
  19. if (odd[y] > odd[y + 1])
  20. {
  21. swapped = true;
  22. int temp = odd[y];
  23. odd[y] = odd[y + 1];
  24. odd[y + 1] = temp;
  25. }
  26. }
  27. }
  28. foreach (int item in odd)
  29. {
  30. Console.Write($"{item:D2} ");
  31. }
  32. Console.WriteLine();
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement