what is wrong with this function? This function insert a new node in the linked list, but it'not works.
thank you in advanceCode:void insertFrontierAstar ( FrontierNodePtr *headPtr, TreeNodePtr ptr ) { FrontierNodePtr currentPtr, previousPtr; FrontierNodePtr newPtr; newPtr = malloc ( sizeof ( FrontierNode ) ); if ( newPtr == NULL ) { printf( "can't allocate memory for FrontierNodePtr\nexit program\n" ); exit ( 3 ); } else { newPtr->leaf = ptr; newPtr->next = NULL; previousPtr = NULL; currentPtr = *headPtr; while ( currentPtr != NULL && currentPtr->leaf->sum < newPtr->leaf->sum ) { previousPtr = currentPtr; currentPtr = currentPtr->next; } if ( previousPtr == NULL ) { newPtr->next = *headPtr; *headPtr = newPtr; return; } if ( currentPtr->leaf->sum > newPtr->leaf->sum ) { previousPtr->next = newPtr; newPtr->next = currentPtr; } if ( currentPtr->leaf->sum == newPtr->leaf->sum ) { while ( currentPtr->leaf->g >= newPtr->leaf->g ) { previousPtr = currentPtr; currentPtr = currentPtr->next; } previousPtr->next = newPtr; newPtr->next = currentPtr; } } }