这是对的吗?我使用了在排序数字时所做的代码,我不知道它是否与字符串相同。当我运行它时,没有检测到错误,但是当我尝试查看它时,输入不会出现。
void add(node **h, node **t){
node *temp, *ptr;
char s[20];
temp = (node*) malloc(sizeof(node));
printf ("-INSERT-");
printf("Fruit: ");
scanf("%s", temp->fruit);
printf("Color: ");
scanf("%s", temp->color);
printf("Texture: ");
scanf("%s", temp->texture);
if ( (*h)->next==(*t) ) {
temp->next = (*h)->next;
temp->prev = (*h);
(*h)->next->prev = temp;
(*h)->next = temp;
}
else{
if(strcmp(s, temp->fruit)){
temp->next = (*h)->next;
temp->prev = (*h);
(*h)->next->prev = temp;
(*h)->next = temp;
}
else if(strcmp(s, temp->fruit)){
temp->next = (*t);
temp->prev = (*t)->prev;
(*t)->prev->next = temp;
(*t)->prev = temp;
}
else{
while(strcmp(s, ptr->fruit)){
ptr = ptr->next;
}
temp->next = ptr->next;
temp->prev = ptr;
ptr->next->prev = temp;
ptr->next = temp;
}
}