# Can't figure out why I am getting segmentation fault

I can't figure out why I am getting a segmentation fault error. Debugging says it is coming from the insert() function. My guess is that I am not allowed to access elements in the array but not sure how to fix this if this is the issue. Below is my insert() function as well as my constructor and the header file. Thank you in advance for any assistance!

```
// Constructor
MinHeap::MinHeap(int cap)
{
heap_size = 0;
capacity = cap + 1;
Node** harr;
harr = new Node*[capacity];
count = 0;
}
// inserts new node into minHeap or replaces root node if full
void MinHeap::insert()
{
if (heap_size + 1 == capacity) {
swapMin();
return;
}
Node* n = new Node();
// First insert the new key at the end
heap_size++;
int i = heap_size;
harr[i] = n;
n->frequency = 1;
n->c = count;
count++;
// Fix the min heap property if it is violated
while (i != 1 && compare(parent(i), i)) {
swap(i, parent(i));
i = parent(i);
}
return;
}
```

Relevant parts of the Header File:

```
class MinHeap
{
public:
struct Node {
int c;
int frequency;
Node* heapElm;
Node* hashElm;
string str;
};
int capacity; // maximum possible size of min heap
int heap_size; // Current number of elements in min heap
int count; // tracks the age of each node in the heap
// Constructor
MinHeap(int capacity);
void insert();
}
```

Please let me know if I can provide anything else that may be helpful.