Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace BubbleSortX
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- bubble_sort(generate_random());
- }
- //private static (int, int) switch_item(int x, int y) => (y, x);
- private static int[] generate_random()
- {
- Random rnd = new Random();
- int[] arryofrand = new int[20];
- for (int i = 0; i < 20; i++)
- {
- arryofrand[i] = rnd.Next(99, 999) + 1;
- }
- return arryofrand;
- }
- private static void bubble_sort(int[] arr)
- {
- {
- for (int i = arr.Length - 1; i > 0; i--)
- {
- for (int j = 0; j < i; j++)
- {
- if (arr[j] > arr[j + 1])
- {
- // switch_item(arr[j],arr[j+1]);
- (arr[j], arr[j + 1]) = (arr[j + 1], arr[j]);
- }
- }
- }
- foreach (int i in arr)
- {
- Console.WriteLine(i);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment