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