Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.78 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 ConsoleApplication3
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int iloscLiczb = 0;
  14.             int[] vals;
  15.  
  16.             Console.Write("Podaj ilosc liczb:");
  17.             while(true)
  18.             {
  19.                 if (int.TryParse(Console.ReadLine(), out iloscLiczb) == false)
  20.                 {
  21.                     Console.Write("Ilosc liczb musi byc wieksza niz 0: ");
  22.                     continue;
  23.                 }
  24.                 if (iloscLiczb < 0)
  25.                 {
  26.                     Console.Write("Ilosc liczb musi byc wieksza niz 0: ");
  27.                     continue;
  28.                 }
  29.                 break;
  30.             }
  31.  
  32.             while(true)
  33.             {
  34.                 Console.Write("Podaj {0} liczb po przecinku: (1, 4, 2): ", iloscLiczb);
  35.                 string[] values = Console.ReadLine().Split(',');
  36.                 if(values.Count() > iloscLiczb)
  37.                     continue;
  38.  
  39.                 vals = new int[iloscLiczb];
  40.                 for (int i = 0; i < values.Count(); i++)
  41.                     vals[i] = int.Parse(values[i]);
  42.  
  43.                 break;
  44.             }
  45.  
  46.             int moves = 0;
  47.             bool isFinished = false;
  48.             while(isFinished == false)
  49.             {
  50.                 Console.Write("#{0}: ", moves);
  51.                     for (int k = 0; k < vals.Count(); k++)
  52.                         Console.Write("{0}, ", vals[k]);
  53.                     Console.WriteLine("");
  54.                     moves += 1;
  55.  
  56.                 // = = = = = Sorting = = = = = //
  57.                 for(int i = 0; i < vals.Count(); i++)
  58.                     if (i + 1 < vals.Count())
  59.                     {
  60.                         if (vals[i + 1] < vals[i])
  61.                         {
  62.                             int temp = vals[i + 1];
  63.                             vals[i + 1] = vals[i];
  64.                             vals[i] = temp;
  65.                             break;
  66.                         }
  67.                     }
  68.  
  69.                 // = = = = = Checking the order = = = = = //
  70.                 for (int i = 0; i <= vals.Count(); i++)
  71.                 {
  72.                     if (i + 1 == vals.Count())
  73.                     {
  74.                         isFinished = true;
  75.                         break;
  76.                     }
  77.  
  78.                     if (vals[i + 1] < vals[i])
  79.                         break;
  80.  
  81.                 }
  82.             }
  83.             Console.Write("#{0}: ", moves);
  84.             for (int k = 0; k < vals.Count(); k++)
  85.                 Console.Write("{0}, ", vals[k]);
  86.             Console.WriteLine("");
  87.                 Console.ReadKey();
  88.             }
  89.  
  90.  
  91.         }
  92.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement