Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 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 ConsoleApp3
  8. {
  9. class Program
  10. {
  11. public class Wezel
  12. {
  13. public Wezel rodzic;
  14. public Wezel prawe;
  15. public Wezel lewe;
  16. public int wartosc;
  17. public int numer;
  18. }
  19.  
  20. public class Drzewo : Wezel
  21. {
  22. public Wezel root = null;
  23. public int length = 0;
  24.  
  25. public void Push(int liczba)
  26. {
  27. var nowy = new Wezel();
  28. nowy.wartosc = liczba;
  29. nowy.numer = length + 1;
  30. if(length == 0)
  31. {
  32. root = nowy;
  33. }
  34. else
  35. {
  36. int tmp = nowy.numer;
  37. List<int> kierunki = new List<int>();
  38. while(tmp>1)
  39. {
  40. kierunki.Add(tmp % 2);
  41. tmp /= 2;
  42. }
  43. var rodzic = root;
  44. for(int i=kierunki.Count - 1;i>=1;i--)
  45. {
  46. if(kierunki[i]==0)
  47. {
  48. rodzic = rodzic.lewe;
  49. }
  50. else
  51. {
  52. rodzic = rodzic.prawe;
  53. }
  54. }
  55. if (kierunki[0] == 0)
  56. {
  57. rodzic.lewe = nowy;
  58. }
  59. else
  60. {
  61. rodzic.prawe = nowy;
  62. }
  63. nowy.rodzic = rodzic;
  64. }
  65. length++;
  66. }
  67. public void Pop()
  68. {
  69.  
  70. }
  71.  
  72.  
  73. }
  74. static void Main(string[] args)
  75. {
  76.  
  77.  
  78. }
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement