order to hardcopy the struct? Or is the next no pointer? O.o Or what is happening there? And I never copied full structures, but just for your interest: This might be slow if the struct to copy is big. Also: You're freeing the memory of head/temp and therefore you copy temp->next to memory that will be freed.
Hole I saw everything right because I have no time and gotta go to work :S
i haven't hardcopied the sruct void delete_from_key(node **head, int key) { node *temp = *head, *prev; if(*head == NULL) { printf("nothing to delete . \n"); return; } else if(temp->num == key) { *head=temp->next; free(temp); return; } while(temp != NULL && temp->num != key ) { prev = temp; temp = temp->next; } if(temp == NULL) { printf("the key is not found\n"); return; } prev->next = temp->next; free(temp); }
Обсуждают сегодня