0
Implement a queue in a circular chained list with head (do functions that implement the operations of Insertion and Removal). The first Row element is in the second cell and the last element is in the cell anterior to the head.
Celula *inserir(Celula *fim, Pessoa *p){
Celula *nova = (Celula*) malloc(sizeof(Celula));
nova->ptrpessoa = p;
nova->prox = fim->prox;
fim->prox = nova;
fim = nova;
return fim;
}
void remover(Celula *ini){
Celula *li = ini->prox;
ini->prox = li->prox;
printf("OPA");
free(li);
}
queue statement
Fila ini;
Fila fim;
to have head I what I do ? I tried so.
Celula cini, cfim;
ini = &cini; /aqui o ini da fila recebe o endereço d cini?
fim = ini; /aqui o final da fila recebe o endereço d cini?
/and here it gets circular ? ini->Prox = ini;
Its functions
inserir
andremover
seem correct (it depends on how you are using them, of course - theremover
for example remove the next one afterini
, which in the case of a row is correct). I didn’t quite understand the doubt: to have a head, all you need is that the initial/special knot does not store elements. How is your data structure? (i.e. what is the relationship betweenFila
andCelula
?)– mgibsonbr
I understood what you meant, but I wanted to know is that the beginning of the queue has to be dps the head and the end before I wanted to know if this implementation that I made is correct in this aspect. cabeca->ini->...->fim->cabeca relaçoes struct pessoa{ char nome[MAX_NOME]; int num; }; typedef struct pessoa Pessoa; struct celula{ Pessoa *ptrpessoa; struct celula *Prox; }; typedef struct celula Celula; typedef struct celula *List; these are the relations
– Matheus Francisco
So the structure is the same, my question was whether
Celula
andFila
were two different things or not. Onlyini
is the head or the first element? Its functionremover
is correct ifini
is the head, otherwise it is incorrect (it will remove the 2nd element). By the way, if the list were double chained it was enough to store the head, but as it is not, it is necessary to store the head and the last (as you are already doing). Anyway, at first glance what you did is ok.– mgibsonbr