Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Implement SelectionSorter.Sort() method using selection sort algorithm
- */
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SortingAndSearchingAlgorithms
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] arrNums = new int[100];
- Random nums = new Random();
- for (int count = 0; count < arrNums.Length; count++ )
- {
- arrNums[count] = nums.Next(0,100);
- }
- for (int i = 0; i < arrNums.Length; i++)
- {
- int min = i;
- int temp = 0;
- for (int j = i + 1; j < arrNums.Length; j++)
- {
- if (arrNums[j] < arrNums[min])
- {
- min = j;
- }
- }
- temp = arrNums[i];
- arrNums[i] = arrNums[min];
- arrNums[min] = temp;
- }
- foreach (int item in arrNums)
- {
- Console.WriteLine(item);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement