【发布时间】:2015-03-19 04:56:03
【问题描述】:
我在双向链表的末尾插入一个节点,但输出只显示第一个和最后一个元素。
void insertend(int y) {
// y the element to be inserted<br>
// head is declared as global
node *ptr=(node*)malloc(sizeof(node));
node *ptr1=head;
ptr->info=y;
if(head==NULL) {
ptr->next=ptr->prev=head;
head=ptr;
}
else {
ptr->prev=ptr1;
ptr->next=NULL;
ptr1->next=ptr;
ptr1=ptr;
}
}
void showtail() {
node *ptr=head;
while(ptr!=NULL) {
printf("%d\n",ptr->info);
ptr=ptr->next;
}
}
这里有什么问题?
【问题讨论】:
-
欢迎来到 *。请修正格式并向我们展示您如何测试您的程序。
-
你可以运行一个调试器来解决这些疑问
-
在发布您的代码时也显示您的结构
标签: c data-structures doubly-linked-list