Unless it's a typo, I see your initialization of dlist
being different from the array: vector<int> dlist(1, depth);
makes a vector of length 1, not depth
. This may possibly cause going out of bounds.
You can always guard against accessing vector elements out of bounds by using dlist.at(currk)
instead of dlist[currk]
, for both reading and writing.