I am trying to build a suffix tree in C ++ as part of a gene sequence assignment
void Tree::insert(string ins)
{
Node* iterator = chooseBranch(root, ins.at(0));
string temp;
for(int i=0; i<100; i++)
{
if(iterator->data=="")
.
.
.
chooseBranch()is a function to choose which of the four children to go to, and I'm trying to check if this Node exists. My Node Class:
struct Node{
Node();
string data;
Node* A;
Node* G;
Node* C;
Node* T;
};
This if statement gives me the segfault that I used gdb to return:
#0 0x0000003ce249bbd6 in std::string::compare () from /usr/lib64/libstdc++.so.6
#1 0x000000000040185b in std::operator==<char, std::char_traits<char>, std::allocator<char> > ()
#2 0x0000000000401305 in Tree::insert ()
#3 0x00000000004016d4 in Tree::Tree ()
#4 0x00000000004010a2 in main ()
What is wrong with this form of checking NULL / how else can I check if Node has data?
source
share