Advertisement
Guest User

Untitled

a guest
May 4th, 2015
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 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 SortArrayOfNum_2
  8. {
  9.     class SortArrayOfNum_2
  10.     {
  11.         static int[] numbers;
  12.  
  13.         //LINQ sorting
  14.         static void LINQSort()
  15.         {
  16.             var newArray = from n in numbers
  17.                            orderby n
  18.                            select n;
  19.  
  20.             foreach (var num in newArray)
  21.             {
  22.                 Console.Write(num+" ");
  23.             }
  24.         }
  25.         // simple sorting algorithm
  26.         static int[] SelectionSort()
  27.         {
  28.             for (int a = 0; a < numbers.Length - 1; a++)
  29.             {
  30.                 int minValue = a;
  31.                 for (int b = a + 1; b < numbers.Length; b++)
  32.                 {
  33.                     if (numbers[b] < numbers[minValue])
  34.                     {
  35.                         minValue = b;
  36.                     }
  37.                 }
  38.                 int temp = numbers[a];
  39.                 numbers[a] = numbers[minValue];
  40.                 numbers[minValue] = temp;
  41.             }
  42.                 return numbers;
  43.         }
  44.         static void Main(string[] args)
  45.         {
  46.             string input = Console.ReadLine();
  47.             numbers = input.Split().Select(int.Parse).ToArray();
  48.  
  49.             Console.WriteLine("LINQ");
  50.             LINQSort();
  51.             Console.WriteLine();
  52.             Console.WriteLine("Seltection Sort");
  53.             SelectionSort();
  54.             foreach (var num in numbers)
  55.             {
  56.                 Console.Write(num+" ");
  57.             }
  58.             Console.WriteLine();
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement