Advertisement
Farhanhm

Untitled

Mar 8th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.38 KB | None | 0 0
  1. static void BubbleSort(int[] array)
  2. {
  3.     while (Sorted(array)==false)
  4.     {
  5.         for (int i=array.Length-1;i>=0;i--)
  6.         {
  7.             if (array[i]<array[i-1])
  8.             {
  9.                 int x = array[i-1];
  10.                 array[i-1]= array[i];
  11.                 array[i]=x;
  12.             }
  13.         }
  14.     }
  15. }
  16. static bool Sorted(int[] array)
  17. {
  18.     for (int i=1;i<array.length;i++)
  19.     {
  20.         if (array[i]<array[i-1])
  21.         {
  22.             return false;
  23.         }
  24.     }
  25.     return true;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement