Advertisement
Hazem3529

Bubblesort

Jan 11th, 2016
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.41 KB | None | 0 0
  1. int[] arr = { 800, 11, 50, 771, 649, 770, 240, 9 };
  2.  
  3. int temp = 0;
  4.  
  5. for (int write = 0; write < arr.Length; write++) {
  6.     for (int sort = 0; sort < arr.Length - 1; sort++) {
  7.         if (arr[sort] > arr[sort + 1]) {
  8.             temp = arr[sort + 1];
  9.             arr[sort + 1] = arr[sort];
  10.             arr[sort] = temp;
  11.         }
  12.     }
  13. }
  14.  
  15. for (int i = 0; i < arr.Length; i++)
  16.     Console.Write(arr[i] + " ");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement