We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Because unlike linked list (std::list), vector iterators become invalidated when you insert. So i++ is causing a segmentation fault. You need to do this:
for (...; /* delete i++ */) {
if ((*i)->left || (*i)->right) {
if ((*i)->left) N.push_back(...)
if ((*i)->right) N.push_back(...)
}
else {
i++;
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Level Order Traversal
You are viewing a single comment's thread. Return to all comments →
Because unlike linked list (std::list), vector iterators become invalidated when you insert. So i++ is causing a segmentation fault. You need to do this: