I am making a directed Graph class. I want find if there is any Cycle and update a vector with it's path accordingly. My Function some times work but others add two times the last edge of the path.So i guess it needs to be tydied up.
Hint: You can hit "edit post", highlight your code and then press the <> formatting button. Note: This will not automatically indent your code! That part is up to you!
I've found it's easiest to copy and paste pre-indented code directly from the IDE, that way it is already properly formatted.
You can use the "preview" button at the bottom to see how it looks.
Using Code Tags, @Handy Andy, from cplusplus.com
Also, what is your computer's operating system, and what IDE or compiler are you using?
Two scary bits in this:
1. You leak memory. The dynamically allocated memory is never released. (Not to mention the lacking copy/move ctors/assignments.)
2. There is no test whether v and w are valid. what would happen in
1 2
Graph g(7);
g.addEdge( 42, 69 );
Lines 45-46 allocate memory too, but where is the delete []?
You do use std::vector already. You could use it more.
bool isCyclicHelp( int, bool [], bool *, vector<int>& ) const
Two array of bool arguments, yet with different syntax? Is that some hint to the reader?
There is no driver to compile and test this class. I would probably make isCyclicHelp() print out what it is doing. (Some prefer debugger for that.)