stefan1919

Sort Array of Numbers Selection Method

Sep 8th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 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 = false;
  21.             while (b != true)
  22.             {
  23.                  b = true;
  24.                 for (int i = 0; i < array.Length - 1; i++)
  25.                 {
  26.                     if (array[i] > array[i + 1])
  27.                     {
  28.                         int help;
  29.                         help = array[i];
  30.                         array[i] = array[i + 1];
  31.                         array[i + 1] = help;
  32.  
  33.                     }
  34.                 }
  35.                 for (int j = 0; j < array.Length - 1; j++)
  36.                 {
  37.                     if (array[j] > array[j + 1])
  38.                     {
  39.                         b = false;
  40.                     }
  41.                 }
  42.             }
  43.             List<int> print = array.ToList();
  44.             for (int i = 0; i < print.Count - 1; i++)
  45.             {
  46.                 if (print[i] == print[i + 1])
  47.                 {
  48.                     print.RemoveAt(i);
  49.                 }
  50.             }
  51.             print.ForEach(i => Console.Write(i + " "));
  52.             }
  53.         }
  54.     }
Advertisement
Add Comment
Please, Sign In to add comment