Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Program
- {
- class Program
- {
- static void selectSort(int[] pole)
- {
- //projede cele pole, zjisti index iMin nejmensiho cisla v poli
- for (int j = 0; j <= pole.Length - 1; j++)
- {
- int iMin = j;
- for (int i = j + 1; i <= pole.Length - 1; i++)
- {
- if (pole[i] < pole[iMin])
- iMin = i;
- }
- //prohozeni cisel pole[j] a pole[iMin]
- /*takto se postupne dostavaji nejmensi cisla doleva na index j
- (nejmensi cislo na index 0, 2. nejmensi na index 1...)*/
- int t = pole[j];
- pole[j] = pole[iMin];
- pole[iMin] = t;
- }
- }
- static void vypisPole(int[] pole)
- {
- for (int i = 0; i < pole.Length; i++)
- Console.Write(pole[i] + " ");
- Console.WriteLine();
- }
- static void Main(string[] args)
- {
- int[] pole = new int[100];
- Random random = new Random();
- for (int i = 0; i < pole.Length; i++)
- pole[i] = random.Next(0, 100);
- Console.WriteLine("Původní pole:");
- vypisPole(pole);
- Console.WriteLine("\n");
- selectSort(pole);
- Console.WriteLine("\nSetřízené pole");
- vypisPole(pole);
- Console.ReadKey();
- }
- }
- }
Add Comment
Please, Sign In to add comment