I'm trying to implement a suffix tree in c++ while adding nodes to my vector list, it throws std::bad_alloc after adding a third element into the tree.
I have no idea why it happens after the third time, Could you help me resolving this error ?
Here's my code :
When you evaluate currentNode[N], you're attempting to access Nth member of an array whose first element is pointed to by the pointer currentNode.. but it is not pointing at an element of any array.
it throws std::bad_alloc after adding a third element into the tree
The first time around, your currentNode->getFils().size() - 1 is zero, so you just reset it back to the same root object, the second time around you move it to uninitialized memory, and third time around you try to access it (undefined behavior then takes place, which just happened to result in a bad_alloc for you - was a segfault for me)