Last active
August 29, 2015 14:20
-
-
Save alagalia/bb2b054de09b98e455fd to your computer and use it in GitHub Desktop.
02 Sort Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
class Program | |
{ | |
static void Main() | |
{ | |
int[] nums = Console.ReadLine().Split().Select(int.Parse).ToArray(); | |
while (true) | |
{ | |
bool check = false; | |
for (int i = 0; i < nums.Length - 1; i++) | |
{ | |
int temp = 0; | |
if (nums[i] > nums[i + 1]) | |
{ | |
temp = nums[i + 1]; | |
nums[i + 1] = nums[i]; | |
nums[i] = temp; | |
check = true; | |
} | |
} | |
if (!check) | |
{ | |
break; | |
} | |
} | |
Console.WriteLine(string.Join(",", nums)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment