So, I have a class with some functions as follows
class MaxHeap{
private:
int _size = 0;
vector<int> arr = {-1};
int p(int i){return i/2;};
int l(int i){return i*2;};
int r(int i){return (i*2)+1;}
public:
bool isEmpty() const {return _size == 0;};
int getMax() const {return arr[1];};
void insertItem(int val);
void shiftUp(int i);
int extractMax();
void shiftDown(int i);
};
and in the main function, if I create two variables like this
MaxHeap* pq1 = new MaxHeap();
MaxHeap pq2;
Will these work same? The arrow operator for the pointer pq1
is the only thing I see as a difference.
I can add elements as follows pq1->insertItem(100);
and pq2.insertItem(100)
.
Is there any difference betweent these two declarations except the arrow operator to access the methods inside the class?