Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _01.SortArrayBubbleSort
- {
- class SortArrayBubbleSort
- {
- static void Main(string[] args)
- {
- int[] arr = Console.ReadLine().Trim().Split(' ')
- .Select(int.Parse).ToArray();
- BubbleSort(arr);
- Console.WriteLine(string.Join(", ", arr));
- } // end static void Main(string[] args)
- static void BubbleSort(int[] array)
- {
- bool swapped = true;
- while (swapped)
- {
- swapped = false;
- for (int i = 0; i < array.Length-1; i++)
- {
- if (array[i] > array[i+1])
- {
- Swap(ref array[i], ref array[i + 1]);
- swapped = true;
- }
- }
- }
- } // end static void BubbleSort(int[] array)
- static void Swap(ref int a, ref int b)
- {
- int temp = a;
- a = b;
- b = temp;
- } // end static void Swap(int a, int b)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement