Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace SortowaniePrzezWstawianie
  8. {
  9. class Program
  10. {
  11. static void Sortowanie(int[] tab)
  12. {
  13. for (int i = 1; i < tab.Length; i++)
  14. {
  15. int wstawiany = tab[i];
  16. int poprzedni = i - 1;
  17. while (poprzedni >= 0 && tab[poprzedni] > wstawiany)
  18. {
  19. tab[poprzedni + 1] = tab[poprzedni];
  20. poprzedni--;
  21. }
  22. tab[poprzedni + 1] = wstawiany;
  23. }
  24. }
  25. static void Main(string[] args)
  26. {
  27. int[] tab = { 4, 1, 5, 3, 2 };
  28. Sortowanie(tab);
  29. foreach (var item in tab)
  30. {
  31. Console.Write(item + " ");
  32. }
  33. Console.ReadKey();
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement