ellapt

DSA2.3.IntListSorted

Jun 1st, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace T3.IntListSorted
  5. {
  6.     class IntListSorted
  7.     {
  8.         static void Main()
  9.         {
  10.             Console.WriteLine("Read sequence of integers (List<int>) ending with empty line.");
  11.             Console.WriteLine("Sort them in an increasing order.");
  12.             Console.WriteLine("Enter integer numbers (or empty line for end):");
  13.             string input = "";
  14.             int number;
  15.             List<int> numList = new List<int>();
  16.             input = Console.ReadLine();
  17.             while (input != "")
  18.             {
  19.                 if ((int.TryParse(input, out number) == true))
  20.                 {
  21.                     numList.Add(number);
  22.                     input = Console.ReadLine();
  23.                 }
  24.                 else
  25.                 {
  26.                     Console.WriteLine("Please, enter only positive integer numbers (or empty line for end):");
  27.                     input = Console.ReadLine();
  28.                 }
  29.             }
  30.  
  31.             int listCount = numList.Count;
  32.             if (listCount == 0)
  33.             {
  34.                 Console.WriteLine("The list is empty.");
  35.             }
  36.             else
  37.             {
  38.                 int count = 0;
  39.                
  40.                 Console.WriteLine("List of the integer numbers you entered: ");
  41.                 while (count < listCount)
  42.                 {
  43.                     Console.Write("{0} ", numList[count]);
  44.                     count++;
  45.                 }
  46.  
  47.                 numList.Sort();
  48.                 count = 0;
  49.                 Console.WriteLine("\nList of integer numbers, sorted: ", listCount);
  50.                 while (count < listCount)
  51.                 {
  52.                     Console.Write("{0} ", numList[count]);
  53.                     count++;
  54.                 }
  55.                 Console.WriteLine();
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment