Search code examples
crecursiondata-structuresdoubly-linked-list

How to remove circular doubly linked iist by using recursion?


i need to write recursive function which will removing all elements fron my circular doubly linked list by using recursion, but i dont have idea which should by the basic condition in this funcition.

void remove_list(struct dll_node **node)
{
    if(){
        free(*node);
        return;
    }

    if(*node){
        remove_list(&(*node)->next);
        free(*node);
    }
}

Solution

  • You just first break the circle

    static int flag=0;
    if (!flag){
        (*node->prev)->next=NULL;
        flag=1;
    }
    

    Then destroy it as if it is a normal double linked list.