Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class SelectionSortArray
- {
- static void Main()
- {
- Console.WriteLine("Insert the length of the array:");
- int n = int.Parse(Console.ReadLine());
- // Read the array
- int[] array = new int[n];
- for (int i = 0; i < n; i++)
- {
- array[i] = int.Parse(Console.ReadLine());
- }
- // Selection Sort
- int currentMin, temp;
- for (int i = 0; i < array.Length - 1; i++)
- {
- currentMin = i;
- for (int j = i + 1; j < array.Length; j++)
- {
- if (array[j] < array[currentMin])
- {
- currentMin = j;
- }
- }
- temp = array[i];
- array[i] = array[currentMin];
- array[currentMin] = temp;
- }
- // Print
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write(array[i] + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement