Advertisement
Guest User

Zad 5

a guest
Mar 30th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. public delegate int porownaj(int a, int b);
  2. public void Zad5_sortowanie(int []tablica, porownaj delegat)
  3. {
  4. int n = tablica.Length;
  5. int tmp = 0;
  6. do
  7. {
  8. for (int i = 0; i < n - 1; i++)
  9. {
  10. if (delegat(tablica[i],tablica[i + 1])<0)
  11. {
  12. tmp = tablica[i];
  13. tablica[i] = tablica[i + 1];
  14. tablica[i + 1] = tmp;
  15. }
  16. }
  17. n--;
  18. } while (n > 1);
  19. }
  20. public void Zad5()
  21. {
  22. wynikTB.Clear();
  23. string s = xTB.Text;
  24. String[] split;
  25. split = s.Split(' ');
  26. int[] liczby = new int[split.Length];
  27. for (int i = 0; i < split.Length; i++)
  28. {
  29. liczby[i] = int.Parse(split[i]);
  30. }
  31. porownaj nazwa = (a, b) =>
  32. {
  33. if (a > b) return 1;
  34. else if (b > a) return -1;
  35. else return 0;
  36. };
  37. Zad5_sortowanie(liczby, nazwa);
  38. foreach(int a in liczby)
  39. {
  40. wynikTB.Text += a.ToString() + " ";
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement