Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections;
- namespace SortVstavki
- {
- 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");
- int[] InsertionSort(int[] arr)
- {
- int[] result = new int[arr.Length];
- for (int i = 0; i < arr.Length; i++)
- {
- int j = i;
- while (j > 0 && result[j - 1] > arr[i])
- {
- result[j] = result[j - 1];
- j--;
- }
- result[j] = arr[i];
- }
- return result;
- }
- int[] res = InsertionSort(arr);
- Console.WriteLine("отсортированный массив: ");
- foreach (int i in res)
- {
- Console.WriteLine(i);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement