Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Program
- {
- class Program
- {
- static void bubbleSort(int[] pole)
- {
- //prvni cyklus pole length krat
- for (int j = 0; j < pole.Length; j++)
- {
- for (int i = 0; i < pole.Length - 1; i++)
- {
- //porovnani sousedicich cisel
- if (pole[i] > pole[i + 1])
- {
- //pokud je cislo vlevo vetsi, vymeni se se sousedicim cislem vpravo
- //takto se postupne dostavaji nejvetsi cisla na konec
- int t = pole[i];
- pole[i] = pole[i + 1];
- pole[i + 1] = t;
- }
- }
- }
- }
- static void vypisPole(int[] pole)
- {
- for (int i = 0; i < pole.Length; i++)
- Console.Write(pole[i] + " ");
- }
- static void Main(string[] args)
- {
- //pole 100 nahodnych cisel
- int[] pole = new int[100];
- Random random = new Random();
- for (int i = 0; i < pole.Length; i++)
- pole[i] = random.Next(0, 100); //rozsah cisel
- //vypsani cisel z pole
- Console.WriteLine("Původní pole: ");
- for (int i = 0; i < pole.Length; i++)
- Console.Write(pole[i] + " ");
- Console.WriteLine("\n");
- bubbleSort(pole);
- Console.WriteLine("\nSetřízené pole: ");
- vypisPole(pole);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment