I am new to C++ and working with STL container at the moment.
I got a serious problem executing a nodeStack.push(startnode)
- the compiler shows up a
Critical error detected c0000374
Followign code shows the function where the mentioned error occurs:
vector<int> Graph::iterativeDepthSearch(map<int, vector<int>> adjlist, int startnode) {
stack<int> nodeStack;
vector<int> visitList;
// Knotenbesuchsliste initialisieren
int* val = new int(adjlist.size());
for (int i = 0; i < (int) adjlist.size(); i++) {
val[i] = 0;
}
int cnt = 1;
nodeStack.push(startnode);
....
}
The error occurs in the line nodeStack.push(startnode);
, startnode is initialized with 0.
try int* val = new int[adjlist.size()];
you are currently allocating a single int and initializing its value, not allocating an array of ints.
The stack structure is corrupting because it is next to your pointer in the memory stack.
nodeStack.push isn't really your problem. You are declaring int* val - a pointer to int, then initializing the integer at val with the size of the list. You really want int *val = new int[adjlist.size()];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With