hey! This is the recent improvement i made.
When i compile I get the following errors:
A.c: In function 'Insert_Queue':
A.c: warning: assignment makes integer from pointer without a cast
A.c: In function 'Delete_Queue':
A.c: warning: assignment makes pointer from integer without a cast
n when i run i get the segmentation error.
When i use gdb to debug i get
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
0x0000000100001bb8 in BFS (start1=5, goal=8) at Adj_mod7.c:284
284 if (goal == queue->info ) {
I tried correcting the warnings but still can get it running fine.
i am posting the main functions for the BFS thing
Code:
struct mainList *find_node( int value)
{
struct mainList *ptr = *pHead;
struct adjList *ptr2 = NULL;
while(ptr != NULL)
{
if(value == ptr->nodeNum)
{
ptr2 = ptr->pAdjListHead;
while(ptr2 != NULL)
{
ptr2 = ptr2->pNext;
}
printf("\n");
}
ptr = ptr->pNext;
}
return ptr;
}
struct Q *Insert_Queue(struct mainList *vertex_no, struct Q *first)
{
struct Q *new1, *current;
new1 =(struct Q *) malloc(sizeof(struct Q));
new1->info = vertex_no; // this a warning , i know of I also tried pointing it to vertex->nodeNum
new1->next = NULL;
if (!first)
return (new1);
for (current = first; current->next; current = current->next);
current->next = new1;
return (first);
}
struct Q *Delete_Queue(struct mainList *vertex_no, struct Q *first)
{
struct Q *previous;
previous =(struct Q *) malloc(sizeof(struct Q));
if (!first)
return (NULL);
vertex_no= first->info;
previous = first;
first = first->next;
free(previous);
return (first);
}
struct Q *insert_unvisited_children(struct Q *queue, struct mainList *search)
{
struct adjList *adj_node;
struct mainList *main_node;
for (adj_node = search->pAdjListHead; adj_node; adj_node = adj_node->pNext)
{
// find the mainList node for this adjList node
main_node = find_node( adj_node->nodeNum);
// if main_node has not been visited, insert it in queue
if(main_node->visited == F )
queue = Insert_Queue(main_node->pNext, queue);
}
return queue;
}
void BFS( int start1, int goal)
{
struct mainList *start, *search, *search1;
struct Q *queue;
// returns a pointer to the mainList node with nodeNum start
start = find_node( start1);
queue = Insert_Queue( start, queue);
while (queue)
{
// extract next node to search
queue = Delete_Queue(search, queue);
// search1 = Delete_Queue(search, queue);
if (goal == queue->info ) {
// we found our node, act accordingly
printf("We found the goall\n");
}
else
{
// set visited to true for search
queue = insert_unvisited_children(queue, search);
search->visited = T;
}
}
}