Dear Stack Overflow,
I have a funny observation which I am not sure if it makes any sense. With regards to your code
/* free rows made by MATRIXint() */
/* where V represents the rows */
for (i = V-1; i >= 0; i--) {
if (G->adj[i] != NULL) {
free(G->adj[i]);
G->adj[i] = NULL;
}
}
/* free 2-dimensional pointer */
if (G->adj != NULL) {
free(G->adj)
G->adj = NULL;
}
/* free Graph */
if (G != NULL) {
free(G);
G = NULL;
}
it appears that when I use it to free up memory used for my graph G in the main program, it works, but when I write it as a function and include it as a header file as follows
void freegraph(G)
{ int i;
/* free rows made by MATRIXint() */
/* where V represents the rows */
for (i = (G->V)-1; i >= 0; i--) {
if (G->adj[i] != NULL) {
free(G->adj[i]);
G->adj[i] = NULL;
}
}
/* free 2-dimensional pointer */
if (G->adj != NULL) {
free(G->adj)
G->adj = NULL;
}
/* free Graph */
if (G != NULL) {
free(G);
G = NULL;
}
it doesn't work. I passed my graph G to this function and then had the following code in my main function
if(G==NULL)printf("success"); else printf("fail");
I got fail instead of the expected success. Why is this so?