typedef struct Individual{
int number_of_la;
double cost;
}Individual;

void  deleteIndividual2(Individual **ind){

    if((*ind)==NULL) return;
    freeLists2(&((*ind)->MSC),1);
    freeLists2(&((*ind)->BSC),1);
    freeLists2(&((*ind)->LA),1);
    freeLists2(&((*ind)->BS),1); 

    (*ind)->MSC=NULL;
    (*ind)->BSC=NULL;
    (*ind)->LA=NULL;
    (*ind)->BS=NULL;
    free((*ind));
    (*ind)=NULL;
}

//LAList-LA-LA_BS ,if includeGroup=1 remove all LAList-LA-LA_BS otherwise List and element will be removed
void freeLists(Network_Element_List *head,int includeGroup){
    Network_Element_List *temp=head;    

    while(temp !=NULL ){
    Network_Element_List *x=temp->next;
    if(includeGroup) freeLists(temp->element->groupHead,0);  
    if(includeGroup) free(temp->element);

    free(temp);     
    temp=x; 
    }       
}

Here are my basic functions above, what i want to do is above first one doesnt work
second one works without any memory error

///11111111111111111111111111111111111111111111(Problem)

Individual **temp_;

temp_=(Individual **)malloc(sizeof(Individual)*5);

temp_[0]=applyMutation(current)
temp_[1]=applyMutation(current)
temp_[2]=applyMutation(current)
temp_[3]=applyMutation(current)
temp_[4]=applyMutation(current)


deleteIndividual2(&temp_[0]);           
deleteIndividual2(&temp_[1]);   
deleteIndividual2(&temp_[2]);
deleteIndividual2(&temp_[3]);
deleteIndividual2(&temp_[4]);


//2222222222222222222222222222222222(working one)

Individual *temp0=NULL,*temp1=NULL,*temp2=NULL,*temp3=NULL,*temp4=NULL;


temp0=applyMutation(current)
temp1=applyMutation(current)
temp2=applyMutation(current)
temp3=applyMutation(current)
temp4=applyMutation(current)


deleteIndividual2(&temp0);              
deleteIndividual2(&temp1);  
deleteIndividual2(&temp2);
deleteIndividual2(&temp3);
deleteIndividual2(&temp4);

Recommended Answers

All 4 Replies

Now, what's your question? Stop over here and read how to properly post your code

Look for this

Individual **temp_;

temp_=(Individual **)malloc(sizeof(Individual)*5);

malloc return a pointer, not double pointer. So you must do memmory allocation in the loop. Better to use C++.(I think)

In addition to listing your code you need to explain what it is that you are expecting your code to do, and what it is doing.

Thanks "zhelih" , you got my point and replied back to me.
For the other friends, my question is that, as you can see that there are two similar code block which operate , on tht point Although first one is works properly , second one does not work.

This code is written for the "Hyperheursitoc method". It does not needed to be underdtand to get my point.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.