Filip13

test_ntp

Oct 29th, 2024
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | Source Code | 0 0
  1. namespace test1
  2. {
  3.     internal class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             int[] array = { 1, 8, -6, 0, 5, 7, 7, 4, 101, 80, 6, -45, -8, -33, 100, -2, 3, 0, 1, 4, -6, 5, -8 };
  8.             BubbleSort(array);
  9.  
  10.             Console.WriteLine(string.Join(" ", array));
  11.         }
  12.  
  13.         private static void BubbleSort(int[] array)
  14.         {
  15.             for (int i = 0; i < array.Length; i++)
  16.             {
  17.                 for (int j = 0; j < array.Length - 1 - i; j++)
  18.                 {
  19.                     if (array[j] > array[j + 1]) //ako treba u obrnutom poretku promeni se znak (>  ->  <)
  20.                     {
  21.                         Swap(array, j, j + 1);
  22.                     }
  23.                 }
  24.             }
  25.         }
  26.  
  27.         private static void Swap(int[] array, int i, int j)
  28.         {
  29.             int tmp = array[i];
  30.             array[i] = array[j];
  31.             array[j] = tmp;
  32.         }
  33.  
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment