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 Sort_Array_Using_Bubble_Sort
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] integers = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToArray();
- BubbleSort(integers);
- string result = string.Join(" ", integers);
- Console.WriteLine(result);
- }
- static void BubbleSort(int[] arr)
- {
- bool swapped = true;
- while (swapped == true)
- {
- swapped = false;
- for (int i = 0; i < arr.Length - 1; i++)
- {
- if (arr[i] > arr[i + 1])
- {
- Swap(ref arr[i], ref arr[i + 1]);
- swapped = true;
- }
- }
- }
- }
- static void Swap(ref int first,ref int second)
- {
- int temp = first;
- first = second;
- second = temp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment