stefan1919

Bubble Sort / + OWN logic

Aug 31st, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication6
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.             string[] inputArray = input.Split(' ');
  15.             int[] array = new int[inputArray.Length];
  16.             for (int i = 0; i < inputArray.Length; i++)
  17.             {
  18.                 array[i] = int.Parse(inputArray[i]);
  19.             }
  20.             bool b = true;
  21.            
  22.             do
  23.             {
  24.                 b = true;
  25.                for (int i = 1; i < array.Length; i++)
  26.             {
  27.                 if (array[i-1] > array[i])
  28.                 {
  29.                     int value = array[i];
  30.                     array[i] = array[i - 1];
  31.                     array[i - 1] = value;
  32.                 }
  33.             }
  34.                for (int j = 1; j < array.Length; j++)
  35.                {
  36.                    if (array[j - 1] > array[j])
  37.                    {
  38.                        b = false;
  39.                    }
  40.                }
  41.             } while (b != true);
  42.             foreach (var item in array)
  43.             {
  44.                 Console.Write(item + " ");
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment