Q:

Warning: control reaches end of non-void function C++

I am trying to implement Prims algorithm to find minimum spanning trees of a given graph.
The code now compiles, but the executable (instead of printing the MST) prints "segmentation fault:11". Moreover, I get a warning, : 
Warning: control reaches end of non-void function

Is anybody able to help me understand what's wrong with it? Thanks in advance.
double Graph::getWeight(int v, int w)
{
    if(edge(v,w))
    {
        Node* t = adj[v];
        while(t != NULL)
        {
            t = t->next;
            if((t ->v) == w)
            return t->weight;
        }
    }
}

A:

The warning is referring to the fact that your getWeight function says it will return a double but actually only returns a double under certain conditions. If either if statement is false (that is, if edge(v,1) is false or if t->v == w is always false), then the function doesn't return anything.
Perhaps you want to return some default value if the conditions are not true.
Whether that is the cause of your segmentation fault is a different matter.

