vojta249

select sort

Mar 30th, 2022
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.45 KB | None | 0 0
  1. using System;
  2.                    
  3. public class Program
  4. {
  5.     public static void Main()
  6.     {
  7.     int[] arr = new int [8] {1,3,2,15,30,20,10,4};
  8.     int n = 8;
  9.     int i, j, k;
  10.         for (i = 0; i < n; i++)
  11.         {
  12.             k = arr[i];
  13.             j=i-1;
  14.            
  15.              while (j >= 0 && arr[j] > k)
  16.             {
  17.                 arr [j+1] = arr [j];
  18.                 j=j-1;
  19.             }  
  20.             arr [j+1] = k;
  21.         }  
  22.       Console.Write("Výsledek:  ");
  23.         foreach (int cislo in arr)
  24.         {
  25.              Console.Write(cislo+", ");
  26.         }
  27.       }
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment