Implement branch deleting with reparent

This commit is contained in:
Dendy 2021-01-24 17:40:31 +01:00
parent fd25215671
commit 91eacbb8c7
Signed by: dendy
GPG Key ID: 0168B35FFD7F608F
3 changed files with 16 additions and 20 deletions

View File

@ -41,29 +41,13 @@ int main(int argc, char* *argv){
NOD_NodeAddChild(bsd, openbsd);
NOD_NodeAddChild(bsd, debianbsd);
NOD_DestroyNodeBranch(bsd);
NOD_DestroyNodeBranch(ubuntu);
//NOD_NodeUnparent(child2);
NOD_PrintNodeTree(distros);
NOD_PrintNodeTree(arch);
NOD_PrintNodeTree(linoox);
NOD_PrintNodeTree(debian);
NOD_PrintNodeTree(freebsd);
NOD_DestroyNode(distros);
NOD_DestroyNode(linoox);
NOD_DestroyNode(debian);
NOD_DestroyNode(ubuntu);
NOD_DestroyNode(mint);
NOD_DestroyNode(devuan);
NOD_DestroyNode(kali);
NOD_DestroyNode(voidlinux);
NOD_DestroyNode(arch);
NOD_DestroyNode(manjaro);
NOD_DestroyNode(parabola);
NOD_DestroyNode(endeavouros);
NOD_DestroyNode(bsd);
NOD_DestroyNode(freebsd);
NOD_DestroyNode(openbsd);
NOD_DestroyNode(debianbsd);
return 0;
}

View File

@ -20,10 +20,21 @@ NOD_Node *NOD_CreateNode(char *name){
void NOD_DestroyNode(NOD_Node *node){
if(node != NULL){
printf("[ INF ] Deleting node \"%s\"\n", node->name);
NOD_NodeUnparent(node);
free(node);
}
}
void NOD_DestroyNodeBranch(NOD_Node *node){
if(node != NULL){
for(int i = 0; i < node->childc && node->childv != NULL; i++){
NOD_DestroyNodeBranch(node->childv[i]);
}
NOD_DestroyNode(node);
}
}
void NOD_NodeAddChild(NOD_Node *parent, NOD_Node *child){
if(parent != NULL && child != NULL){
/** Prevent recursion */

View File

@ -15,6 +15,7 @@ typedef struct node{
NOD_Node *NOD_CreateNode(char *name);
void NOD_DestroyNode(NOD_Node *node);
void NOD_DestroyNodeBranch(NOD_Node *node);
void NOD_NodeAddChild(NOD_Node *parent, NOD_Node *child);
void NOD_NodeUnparent(NOD_Node *child);