I am trying to print an array of linked lists. I am having trouble getting it to print. Here is my struct.
typedef struct VERTEXTAG
{
char c;
bool isvisited;
struct EDGETAG* p;
}VERTEX;
typedef struct EDGETAG
{
VERTEX* v;
struct EDGETAG* q;
//cookies rock
//I like cookies
}EDGE;
Here are my variable declarations
VERTEX v[100];
EDGE *e;
EDGE* temp;
int counter = 0;
int addcounter = 0;
int i = 0;
Here is where I try to create the linked lists. I have an even case and an odd case.
//even case
if(counter - i == 1 && flag == 0)
{
vertices[addcounter] = (char)c;
//printf("The vertice is %c :\n", vertices[addcounter]);
e = (EDGE*) malloc(sizeof(EDGE));
v[addcounter].p=e;
v[addcounter].c= (char)c;
v[addcounter].isvisited=false;
v[addcounter].p=NULL;
addcounter++;
}
//odd case
if(counter - i == 1 && flag == 0)
{
vertices[addcounter] = (char)c;
//printf("The vertice is %c :\n", vertices[addcounter]);
e = (EDGE*) malloc(sizeof(EDGE));
v[addcounter].p=e;
v[addcounter].c= (char)c;
v[addcounter].isvisited=false;
v[addcounter].p=NULL;
(*e).v= &v[addcounter];
e->q = NULL;
addcounter++;
}
Here is where I try to print my linked list. For some reason temp is equal to NULL so it is not printing. I know I am correctly passing my variables to each case with vertices array. It prints out correctly. I am not sure if I am correctly creating the linked list of arrays since it will not print out.
temp = v[0].p;
if(temp == NULL)
{
printf("Temp is Null\n");
}
while(temp != NULL)
{
printf("While loop");
printf("%c", (*(*temp).v).c);
temp = temp->q;
}
printf("The vertice is %s :\n", vertices);