original code: Original Code.txt - Google Drive
modded code: Modded code (heap to stack).txt - Google Drive
THE MODDED CODE DOESN’T RUN. Needs inspection.
i sought to convert declarations done using the ‘new’ keyword, in original code, to standard stack declarations.
please see now, brother. It will be easier now. Just copy n paste
1 Like
tell me what u get, bro
class Graph
{
// ...
list<int> *adj;
// ...
};
Graph::Graph(int V)
{
this->V = V;
list<int> s[V];
adj=s; // Taking pointer to local variable.
}
void Graph::addEdge(int v, int w)
{
// Using pointer to local variable from expired stack frame - Undefined Behaviour.
adj[v].push_back(w); // Add w to v’s list.
}
1 Like
yup, exactly, bro !
but what happens to the memory address (of expired list ) which got stored in adj?
i ran the debugger and found that the address was still stored in adj