Could anyone help with this (I guess pointer and memory allocation problem-- At run time the code does not work if I remove the //COMMENTED// cout statement
The two *in
and *out
of struct data structure E although treated in the same manner, only the *in gives me the output as desired
struct V
{
int al;
V *next;
};
struct E
{;
int id;
V *in;
V *out;
};
void init(E *edges, int count)
{
int i = 0;
int id = 1;
while (i < count)
{
edges[i].id = id;
edges[i].out = new V;
edges[i].out->al = 0;
edges[i].out->next = NULL;
edges[i].in = new V;
edges[i].in->al = 0;
edges[i].in->next = NULL;
i++; id++;
}
i =0;
while (i < count)
{
cout<<"Edges are:"<<endl;
cout<<"Edge In "<<i<<" is "<<edges[i].in->al<<endl;
//cout<<"Edge Out "<<i<<" is "<<edges[i].out->al<<endl;
i++;
}
}
int main()
{
int counter=5;
E *edges = new E[counter];
init(edges,counter);
}