Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace buble_sort
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
- BubbleSort(array);
- Console.WriteLine(string.Join(" ", array));
- }
- static void BubbleSort(int[] array)
- {
- bool swapped;
- do
- {
- swapped = false;
- for (int index = 0; index < array.Length-1; index++)
- {
- if (array[index] > array[index+1])
- {
- Swap(array,index, index + 1);
- swapped = true;
- }
- }
- } while (swapped);
- }
- static void Swap(int[] array, int index1, int index2)
- {
- int temp = array[index1];
- array[index1] = array[index2];
- array[index2] = temp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement