Advertisement
Guest User

shell_sort

a guest
Jan 29th, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. private void Shell(object sender, RoutedEventArgs e) // Сортировка Шелла
  2.         {
  3.             int[] localList = (int[])unsorted.Clone();
  4.             DateTime t0 = DateTime.Now;
  5.             int d = localList.Length / 2;
  6.             while (d > 0)
  7.             {
  8.                 for (int i = 0; i < localList.Length - d; i++)
  9.                 {
  10.                     if (localList[i] > localList[i + d])
  11.                     {
  12.                         int temp = localList[i];
  13.                         localList[i] = localList[i+d];
  14.                         localList[i+d] = temp;
  15.                     }
  16.                    
  17.                 }
  18.                 d /= 2;
  19.             }
  20.             for (int i = 0; i < localList.Length - 1; i++)
  21.             {
  22.                 for (int j = i; j < localList.Length; j++)
  23.                 {
  24.                     if (localList[i] > localList[j])
  25.                     {
  26.                         int temp = localList[i];
  27.                         localList[i] = localList[j];
  28.                         localList[j] = temp;
  29.                     }
  30.                 }
  31.             }
  32.             DateTime t1 = DateTime.Now;
  33.             Console.WriteLine("Время сортировки составило: " + CalculateTime(t0, t1) + " мс");
  34.             string msg = "";
  35.             foreach (int elem in localList)
  36.             {
  37.                 msg += elem + ", ";
  38.             }
  39.             MessageBox.Show(msg);
  40.  
  41.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement