Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections;
- namespace sortSelection//сортировка выбором
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Введите неотсортированный массив");
- int[] arr = new int[10];
- for (int i = 0; i < arr.Length; i++)
- {
- arr[i] = Convert.ToInt32(Console.ReadLine());
- }
- Console.WriteLine("\n\n");
- arr = SelectionSort(arr);
- foreach(int i in arr)
- {
- Console.WriteLine(i);
- }
- }
- public static int[] SelectionSort(int[] arr)
- {
- for(int i = 0; i < arr.Length - 1; i++)
- {
- int min = i;
- for(int j = i + 1; j < arr.Length; j++)
- {
- if(arr[j] < arr[min])
- {
- min = j;
- }
- }
- int temp = arr[i];
- arr[i] = arr[min];
- arr[min] = temp;
- min = i;
- }
- return arr;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement