void removetree(Node* &root) { if(NULL == root) return ; removetree(root->ch[0]); removetree(root->ch[1]); delete root; root = NULL; }
//--------------------------------------------------------------------------------------------------------------------// //Afairese tis perites parenthesis apo ena dentro parenthesis * simplify(parenthesis * input) { int i=0; parenthesis ** kids=input->subparenthesis; parenthesis * temporal; char * temp=(char*) malloc(MAX); if(temp== NULL) { fprintf(stderr, "out of memory\n"); return NULL; } if((input->kids)==1) { strcpy(temp,kids[0]->content); wrapwithparenthesis(temp); if(!strcmp(temp,input->content)) { replacement(input->content,input->content, kids[0]->content); temporal=addpar(input->content,input->parent,NULL,input->num,input->depth); removetree(input); free(input); } else { return input; } temporal=simplify(temporal); free(temp); return temporal; } else if ((input->kids)>1) { for(i=0;i<input->kids;i++) { strcpy(temp,(kids[i]->content)); kids[i]= simplify(kids[i]); replacement(input->content,temp, kids[i]->content); temporal=addpar(input->content,input->parent,NULL,input->num,input->depth); removetree(input); free(input); input=temporal; kids=input->subparenthesis; } free(temp); } else { free(temp); return input; } return input; }
void init() { for(int i = 1;i <= n;i++) { removetree(root[i]); root[i] = new Node(wei[i]); set[i] = i; } for(int i = 1;i <= m;i++) if(true == exist[i]) add_edge(edge[i].first,edge[i].second); }
//--------------------------------------------------------------------------------------------------------------------// //Diagrafh to dentro kai ta dedomena tou l-orou void removetree(parenthesis * par) { int i; if (!(par->content))return; parenthesis ** kido=par->subparenthesis; i=0; while (i<(par->kids)) { removetree(kido[i]); free(kido[i]); i++; } for (i=0;(i<MAX);i++) { free((par->variables)[i]); } free(par->variables); free(par->content); free(par->subparenthesis); }