Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Sortign
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] numbers = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
- bubbleSort(numbers);
- printArray(numbers);
- }
- static void bubbleSort(int[] arr)
- {
- int n = arr.Length;
- for (int i = 0; i < n - 1; i++)
- for (int j = 0; j < n - i - 1; j++)
- if (arr[j] > arr[j + 1])
- {
- // swap temp and arr[i]
- int temp = arr[j];
- arr[j] = arr[j + 1];
- arr[j + 1] = temp;
- }
- }
- static void printArray(int[] arr)
- {
- int n = arr.Length;
- for (int i = 0; i < n; ++i)
- Console.Write(arr[i] + " ");
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement