Advertisement
GogoK

BubbleSort

May 4th, 2015
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. class SortArray
  5. {
  6.     static void Main()
  7.     {
  8.         int[] nums = Console.ReadLine().Split().Select(int.Parse).ToArray();
  9.         while (true)
  10.         {
  11.             bool check = false;
  12.             for (int i = 0; i < nums.Length - 1; i++)
  13.             {
  14.                 int temp = 0;
  15.                 if (nums[i] > nums[i + 1])
  16.                 {
  17.                     temp = nums[i + 1];
  18.                     nums[i + 1] = nums[i];
  19.                     nums[i] = temp;
  20.                     check = true;
  21.                 }
  22.             }
  23.             if (!check)
  24.             {
  25.                 foreach (var digit in nums)
  26.                 {
  27.                     Console.Write("{0}, ", digit);
  28.                 }
  29.                 Console.WriteLine("\b\b ");
  30.                 break;
  31.             }
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement