Advertisement
Cyzol

dla ogryza

Nov 20th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. template <typename T>
  2. class Heap {
  3. public:
  4. T* dane;
  5. int capacity;
  6. int size;
  7. Heap()
  8. {
  9. size = 0;
  10. capacity = 6;
  11. dane = new T[capacity];
  12. }
  13. void AddNewElement(const T&cos)
  14. {
  15. //Jesli rozmiar jest mniejszy niz pojemnnosc
  16. if (size <= capacity) {
  17. dane[size] = cos;
  18. size += 1;
  19. }
  20. else
  21. //Jesli rozmiar jest wiekszy niz pojemnosc, to trzeba rozszerzyc
  22. {
  23.  
  24. }
  25. }
  26. };
  27.  
  28.  
  29.  
  30. template <typename T>
  31. void swap(T* x, T* y)
  32. {
  33. T* temp;
  34. temp = x;
  35. x = y;
  36. y = temp;
  37. }
  38.  
  39. template <typename T>
  40. T parent(T indeks)
  41. {
  42. return (indeks - 1) / 2;
  43. }
  44.  
  45. int main()
  46. {
  47. Heap<int>* heap = new Heap<int>();
  48. heap->AddNewElement(1); //0
  49. heap->AddNewElement(2); //1
  50. heap->AddNewElement(3); //2
  51. heap->AddNewElement(4); //3
  52. heap->AddNewElement(5); //4
  53. //cout << heap->dane[0] << endl;
  54. //swap(heap->dane[0], heap->dane[1]);
  55. //cout << heap->dane[0] << endl;
  56. cout << parent(3);
  57. cout << heap->dane[parent(3)] << endl;
  58. delete heap;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement