Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SortowaniePrzezWstawianie
- {
- class Program
- {
- static void Sortowanie(int[] tab)
- {
- for (int i = 1; i < tab.Length; i++)
- {
- int wstawiany = tab[i];
- int poprzedni = i - 1;
- while (poprzedni >= 0 && tab[poprzedni] > wstawiany)
- {
- tab[poprzedni + 1] = tab[poprzedni];
- poprzedni--;
- }
- tab[poprzedni + 1] = wstawiany;
- }
- }
- static void Main(string[] args)
- {
- int[] tab = { 4, 1, 5, 3, 2 };
- Sortowanie(tab);
- foreach (var item in tab)
- {
- Console.Write(item + " ");
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement