Advertisement
Guest User

Untitled

a guest
Jun 16th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. /*
  2.  * Implement SelectionSorter.Sort() method using selection sort algorithm
  3.  
  4.  */
  5.  
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11.  
  12. namespace SortingAndSearchingAlgorithms
  13. {
  14.     class Program
  15.     {
  16.         static void Main(string[] args)
  17.         {
  18.             int[] arrNums = new int[100];
  19.             Random nums = new Random();
  20.  
  21.             for (int count = 0; count < arrNums.Length; count++ )
  22.             {
  23.                 arrNums[count] = nums.Next(0,100);
  24.             }
  25.  
  26.             for (int i = 0; i < arrNums.Length; i++)
  27.             {
  28.                 int min = i;
  29.                 int temp = 0;
  30.                 for (int j = i + 1; j < arrNums.Length; j++)
  31.                 {              
  32.                     if (arrNums[j] < arrNums[min])
  33.                     {
  34.                         min = j;
  35.                     }
  36.                 }
  37.  
  38.                 temp = arrNums[i];
  39.                 arrNums[i] = arrNums[min];
  40.                 arrNums[min] = temp;
  41.             }
  42.  
  43.             foreach (int item in arrNums)
  44.             {
  45.                 Console.WriteLine(item);
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement