Prince_81
29-09-2008, 16:39
sto cercando di creare una lista bidirezionale ma ho alcuni problemi con le function di inserimento :
void ins_testa(short len_info,INFO_FIELD *dato,void **p_head){
struct lista{INFO_FIELD info;struct lista *next;struct lista *prec;}*ptr;
ptr=calloc(1,sizeof(struct lista));
ptr->next = NULL;
ptr->prec = NULL;
memcpy(ptr,dato,len_info);
if(*p_head != NULL){
((struct lista *)*p_head)->prec=ptr;
}
ptr->next=(struct lista *)*p_head;
(struct lista *)*p_head=ptr;
}
void ins_nodo(short len_info,INFO_FIELD *dato,void **punt){
struct lista{INFO_FIELD info;struct lista *next;struct lista *prec;}*ptr;
ptr=calloc(1,sizeof(struct lista));
ptr->next = NULL;
ptr->prec = NULL;
memcpy(ptr,dato,len_info);
ptr->next=((struct lista *)*punt)->next;
((struct lista *)*punt)->next=ptr;
ptr->prec = *punt;
if (ptr->next != NULL)
(ptr->next)->prec=ptr;
((struct lista *)*punt)=ptr;
}
Sapreste dirmi cosa non va? grazie
void ins_testa(short len_info,INFO_FIELD *dato,void **p_head){
struct lista{INFO_FIELD info;struct lista *next;struct lista *prec;}*ptr;
ptr=calloc(1,sizeof(struct lista));
ptr->next = NULL;
ptr->prec = NULL;
memcpy(ptr,dato,len_info);
if(*p_head != NULL){
((struct lista *)*p_head)->prec=ptr;
}
ptr->next=(struct lista *)*p_head;
(struct lista *)*p_head=ptr;
}
void ins_nodo(short len_info,INFO_FIELD *dato,void **punt){
struct lista{INFO_FIELD info;struct lista *next;struct lista *prec;}*ptr;
ptr=calloc(1,sizeof(struct lista));
ptr->next = NULL;
ptr->prec = NULL;
memcpy(ptr,dato,len_info);
ptr->next=((struct lista *)*punt)->next;
((struct lista *)*punt)->next=ptr;
ptr->prec = *punt;
if (ptr->next != NULL)
(ptr->next)->prec=ptr;
((struct lista *)*punt)=ptr;
}
Sapreste dirmi cosa non va? grazie