Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename T>
- class Heap {
- public:
- T* dane;
- int capacity;
- int size;
- Heap()
- {
- size = 0;
- capacity = 6;
- dane = new T[capacity];
- }
- void AddNewElement(const T&cos)
- {
- //Jesli rozmiar jest mniejszy niz pojemnnosc
- if (size <= capacity) {
- dane[size] = cos;
- size += 1;
- }
- else
- //Jesli rozmiar jest wiekszy niz pojemnosc, to trzeba rozszerzyc
- {
- }
- }
- };
- template <typename T>
- void swap(T* x, T* y)
- {
- T* temp;
- temp = x;
- x = y;
- y = temp;
- }
- template <typename T>
- T parent(T indeks)
- {
- return (indeks - 1) / 2;
- }
- int main()
- {
- Heap<int>* heap = new Heap<int>();
- heap->AddNewElement(1); //0
- heap->AddNewElement(2); //1
- heap->AddNewElement(3); //2
- heap->AddNewElement(4); //3
- heap->AddNewElement(5); //4
- //cout << heap->dane[0] << endl;
- //swap(heap->dane[0], heap->dane[1]);
- //cout << heap->dane[0] << endl;
- cout << parent(3);
- cout << heap->dane[parent(3)] << endl;
- delete heap;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement