Problems deleting certain element from a list within another linked list

1

I'm having a problem removing an element, I have a function that is responsible for deleting the element within doubly chained lists.

How does it work?

In the main function is called the name of an element (movie) in which to remove. This element is allotted to a list of actors (there is a list of movies for actors) and there is a list of films (with a list of actors that are part of it).

What do I need to do?

I need to delete this element from the list of movies that is contained in the list of actors and if the actor owns only that film that is being removed it is necessary to also remove the actor from the general list of actors.

What have I done so far? (briefly the main part that is in trouble)

.
.
.
typedef struct filme{
    char nome[P];
    char ano[14];
    struct duplaAt *listaAtores;
    struct duplaDir *listaDiretores;
    struct filme *next;
    struct filme *prev;
}filme;

typedef struct Ator{
    char nome[P];
    struct duplaFilm *listaFilmes;
    struct Ator *next;
    struct Ator *prev;
}ator;
typedef struct duplaAt{
    struct Ator *at;
    struct duplaAt *next;
    struct duplaAt *prev;
}duplaAt;
typedef struct duplaFilm{
    struct filme *fil;
    struct duplaFilm *next;
    struct duplaFilm *prev;
}duplaFilm;
void excluirAtRef(char auxInsert[P], struct Ator ** inicioAtores,struct Ator ** fimAtores)
{
    printf("\n TO AQUI! 1");
    struct Ator * atorHead=*inicioAtores;
    struct duplaFilm *refFilme;
    int band;
        while(atorHead!=NULL)
             {
                band=1;
                refFilme=atorHead->listaFilmes;
                while(refFilme!=NULL)
                 {
                    if(strcmp(refFilme->fil->nome,auxInsert)==0)
                 {
                    //flag
                      if(refFilme->prev==NULL && refFilme->next==NULL)
                      {
                       printf("\n TO AQUI! 2 :%s",atorHead->nome);
                       free(refFilme);
                        band=0; 
                      }
                       else if(refFilme->prev==NULL && refFilme->next!=NULL)
                      {

                       refFilme->next->prev=NULL;
                       free(refFilme);
                    printf("\n TO AQUI! 3: %s",atorHead->nome);

                      }
                else if(refFilme->prev!=NULL && refFilme->next!=NULL)
                 {
                     refFilme->prev->next = refFilme->next;
                    refFilme->next->prev = refFilme->prev;
                    free(refFilme);
                printf("\n TO AQUI! 4");

                 }
                else if(refFilme->prev!=NULL && refFilme->next==NULL)
                 {
                    refFilme->prev->next = NULL;

                    free(refFilme);
                    printf("\n TO AQUI! 5");
                 }



                 }
                    refFilme=refFilme->next;
                 }



                if(band==0)
                 {
                 if(atorHead->prev==NULL && atorHead->next==NULL)
                 {
                    *inicioAtores=NULL;
                    *fimAtores=NULL;
                    free(atorHead);
                    printf("\n ATOR TO AQUI!");
                 }
                else if(atorHead->prev==NULL && atorHead->next!=NULL)
                 {
                    atorHead->next->prev = NULL;
                    *inicioAtores = atorHead->next;

                    free(atorHead);
                    printf("\n ATOR TO AQUI! 2");
                 }
                else if(atorHead->prev!=NULL && atorHead->next!=NULL)
                 {
                    atorHead->prev->next = atorHead->next;
                    atorHead->next->prev = atorHead->prev;
                    free(atorHead); 
                    printf("\n ATOR TO AQUI! 3");
                 }
                else if(atorHead->prev!=NULL && atorHead->next==NULL)
                 {
                    atorHead->prev->next = NULL;
                    *fimAtores= atorHead->prev;

                    free(atorHead);
                    printf("\n ATOR TO AQUI! 4");
                 }

                 }

                atorHead=atorHead->next;
             }  

}

What is the problem?

Removing the last element from the list of movies in the actors is removing the actor. (And this theoretically should not be happening because the flag band is only 0 when the movie is single in the list.)

    
asked by anonymous 01.07.2018 / 18:41

0 answers