angryatti

BubbleSortXCsharpArrayVersion

Dec 23rd, 2025
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. namespace BubbleSortX
  2. {
  3.     internal class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             bubble_sort(generate_random());
  8.         }
  9.         //private static (int, int) switch_item(int x, int y) => (y, x);
  10.         private static int[] generate_random()
  11.         {
  12.             Random rnd = new Random();
  13.  
  14.             int[] arryofrand = new int[20];
  15.  
  16.  
  17.             for (int i = 0; i < 20; i++)
  18.             {
  19.  
  20.                 arryofrand[i] = rnd.Next(99, 999) + 1;
  21.  
  22.  
  23.             }
  24.             return arryofrand;
  25.  
  26.         }
  27.         private static void bubble_sort(int[] arr)
  28.         {
  29.             {
  30.                 for (int i = arr.Length - 1; i > 0; i--)
  31.                 {
  32.                     for (int j = 0; j < i; j++)
  33.                     {
  34.                         if (arr[j] > arr[j + 1])
  35.                         {
  36.                             // switch_item(arr[j],arr[j+1]);
  37.                             (arr[j], arr[j + 1]) = (arr[j + 1], arr[j]);
  38.                         }
  39.                     }
  40.                 }
  41.                 foreach (int i in arr)
  42.                 {
  43.                     Console.WriteLine(i);
  44.                 }
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment