My problem is removing the node from the linked list.
I have two structures:
typedef struct inner_list
{
int count;
char word[100];
inner_list*next;
} inner_list;
typedef struct outer_list
{
char word [100];
inner_list * head;
int count;
outer_list * next;
} outer_list;
My problem is removing the node from the linked external_list. For example, when a user entered aaais deleted delete function should find the node with outer_list->word = aaa and delete this node and reconnect the list again. I tried the code below to do this. but after detection and deletion I lose the list. I do not know what happened. Note that outer_list also has a linked inner_list inside.
void delnode(outer_list **head,char num[100])
{
outer_list *temp, *m;
m=temp=*head;
while(temp!=NULL) {
if(strcmp(temp->word,num)==0) {
if(temp==*head) {
delinner(temp->head);
*head=temp->next;
free(temp);
return;
} else {
delinner(temp->head);
m->next=temp->next;
free(temp);
return;
}
} else {
m=temp;
temp= temp->next;
}
}
printf(" ELEMENT %s NOT FOUND ", num);
}
void delinner(inner_list *head) {
inner_list *temp;
temp=head;
while(temp!=NULL) {
head=temp->next;
free(temp);
temp=head;
}
}
Now my problem is updated. When removing an item from an internal list, I also try to remove the same item from inner_list too.
: - say aaa - outer_list, external_list * p
- , . ( p- > .) . _, , head_list, .
:
void delnode2(outer_list *up,inner_list **head,char num[100])
{
inner_list *temp2,*temp, *m;
outer_list *p;
p = up;
while(p!=NULL){m=temp=temp2=p->head;
while(temp!=NULL) {
if(strcmp(temp->word,num)==0) {
if(temp==(*head)) {
*head=temp->next;
free(temp);
return;
} else {
m->next=temp->next;
free(temp);
return;
}
} else {
m=temp;
temp= temp->next;
}
}
p=p->next;
}
printf(" ELEMENT %s NOT FOUND ", num);
}
node _ external_list , , , . , . .