Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class SelectionSortAlg_07
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int[] arr = new int[n];
- int temp = 0;
- int min = 0;
- for (int i = 0; i < n; i++)
- {
- arr[i] = int.Parse(Console.ReadLine());
- }
- for (int j = 0; j < arr.Length-1; j++){
- min = j;
- for ( int m = j+1; m < arr.Length; m++) {
- if (arr[m] < arr[min])
- {
- min = m;
- }
- }
- if (j != min)
- {
- temp = arr[j];
- arr[j] = arr[min];
- arr[min] = temp;
- }
- }
- for (int i = 0; i < arr.Length; i++)
- {
- Console.WriteLine("Element[{0}] = {1}", i, arr[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment