编写一个函数以从链表中删除一个元素,该函数接收一个参数 10
#include<stdio.h>structentry{intvalue;structentry*next;};voidmain(){voidremoveEntry(s...
#include<stdio.h>
struct entry
{
int value;
struct entry *next;
}
;
void main()
{
void removeEntry(struct entry *n);
struct entry n1,n2,n3,ListHead;
struct entry *list=&n1;
n1.value=100;
n2.value=200;
n3.value=300;
n3.next=(struct entry*)0;
ListHead.next=&n1;
n1.next=&n2;
n2.next=&n3;
removeEntry(&n1);
while(list)
{
printf("%i\n",list->value);
list=list->next;
}
}
void removeEntry(struct entry *n)
{
n->next=(n+1)->next;
}
为什么显示100和一个很奇怪的数字。怎么用函数传递一个参数实现删除一个链表元素这个功能。 展开
struct entry
{
int value;
struct entry *next;
}
;
void main()
{
void removeEntry(struct entry *n);
struct entry n1,n2,n3,ListHead;
struct entry *list=&n1;
n1.value=100;
n2.value=200;
n3.value=300;
n3.next=(struct entry*)0;
ListHead.next=&n1;
n1.next=&n2;
n2.next=&n3;
removeEntry(&n1);
while(list)
{
printf("%i\n",list->value);
list=list->next;
}
}
void removeEntry(struct entry *n)
{
n->next=(n+1)->next;
}
为什么显示100和一个很奇怪的数字。怎么用函数传递一个参数实现删除一个链表元素这个功能。 展开
1个回答
展开全部
错误太多 无法吐槽 反映基础还不是很好 自己帮你写了一个 你参考一下 不懂再问
#include<stdio.h>
struct entry
{
int value;
struct entry *next;
};
void removeEntry(struct entry *n)
{
entry *nextNode = n->next;
n->next = nextNode->next;
delete nextNode;
}
void main()
{
struct entry *n1,*n2,*n3;
n1 = new struct entry;
n2 = new struct entry;
n3 = new struct entry;
n1->value=100;
n2->value=200;
n3->value=300;
n3->next=(struct entry*)0;
n1->next=n2;
n2->next=n3;
struct entry *list = n1;
removeEntry(n1);
while(list)
{
printf("%i\n",list->value);
list=list->next;
}
}
#include<stdio.h>
struct entry
{
int value;
struct entry *next;
};
void removeEntry(struct entry *n)
{
entry *nextNode = n->next;
n->next = nextNode->next;
delete nextNode;
}
void main()
{
struct entry *n1,*n2,*n3;
n1 = new struct entry;
n2 = new struct entry;
n3 = new struct entry;
n1->value=100;
n2->value=200;
n3->value=300;
n3->next=(struct entry*)0;
n1->next=n2;
n2->next=n3;
struct entry *list = n1;
removeEntry(n1);
while(list)
{
printf("%i\n",list->value);
list=list->next;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询