Program : CYK Algorithm,
I did it using strings and vectors.
Code is compiling without any syntax errors and also asking me to Enter string
but there is something wrong in the 69th line i guess..
It is saying CYK.exe has stopped working!
can anyone please help me out with this!
Line 69 you create an array of len vectors. Each vector will be empty so on line 78 you try to access elements that doesn't exists. Before you access an element in a vector you have to make sure it has that many elements.
You can use push_back to add one element
1 2
// Adds an empty string to the end of vector TT[i]
TT[i].push_back("");
Or you might want to use resize.
1 2
// Sets the size of vector TT[i] to len (All new string elements will be empty)
TT[i].resize(len);
@peter87 Thanks a lot for your help.
I've rectified it.
But my problem is not solved yet.
still getting the same error.
Note that the cout statement in line 70 is NOT executing!!
Kindly help
How do you know that it's not executing? You don't flush cout so it might very well run even though you see no output. Use one of the following lines instead.
1 2 3
cout<<"dhjdfal"; cout.flush();
cout<<"dhjdfal" << flush;
cout<<"dhjdfal" << endl; // This will also print a newline character.
I used one of those lines as you said and I tried all three of them and I'm seeing no output of that 70th line.
May be according to you that cout statement is executing but not showing output. okay!
But where is the problem now?
Why is my program not executing??
What is the problem now??
I've done everything as you told :\
HELP!!
When I run your program I don't get past the first loop (line 16-21) because I don't have the file CYK.txt. Does it give any output at all for you? Maybe you should add a few more cout statements (with flushing) or simply use a debugger to find out where things go wrong.
just create a text file CYK.txt in the same directory in which you downloaded this code and write the following in the file
S->AB|BC
A->BA|a
B->CC|b
C->AB|a
and save it.
and yes it gives me output of the file contents as i asked and also asks me to "Enter the string" .
and after i enter the string.
it gives the output as dhjdfal and hungs.. help!!