C语言 链表插入问题
在某个节点后边插入;看一下里面对不对,有那些不知道意思的可以问我voidtable_insert(structtable*tab,structnode*newNode,s...
在某个节点后边插入;
看一下里面对不对,有那些不知道意思的可以问我
void table_insert(struct table *tab, struct node *newNode, struct node *depand) {
struct node *temporary_data;
temporary_data = depand;
if (tab->head == NULL) {
newNode = tab->head;
depand = newNode;
depand->next = NULL;
tab->end = depand;
} else {
if (tab->head == depand) {
newNode = tab->head;
depand = newNode->next;
} else {
temporary_data = depand->next;
newNode = depand->next;
temporary_data = newNode->next;
}
}
}
struct node {
char name[10];
int age;
struct node *next;
};
struct table {
struct node *head;
struct node *end;
size_t size;
}; 展开
看一下里面对不对,有那些不知道意思的可以问我
void table_insert(struct table *tab, struct node *newNode, struct node *depand) {
struct node *temporary_data;
temporary_data = depand;
if (tab->head == NULL) {
newNode = tab->head;
depand = newNode;
depand->next = NULL;
tab->end = depand;
} else {
if (tab->head == depand) {
newNode = tab->head;
depand = newNode->next;
} else {
temporary_data = depand->next;
newNode = depand->next;
temporary_data = newNode->next;
}
}
}
struct node {
char name[10];
int age;
struct node *next;
};
struct table {
struct node *head;
struct node *end;
size_t size;
}; 展开
展开全部
我帮你改一下,你试试
void table_insert(struct table *tab, struct node *newNode, struct node *depand) {
struct node *temporary_data, *p;
p = tab->head;
do{
if (tab->head == NULL) {
tab->head = newNode;
newNode->next = NULL;
tab->end = newNode;
break;
} else {
if (tab->head == depand) {
depand ->next = newNode;
newNode->next = NULL;
if(depand == tab->end;
tab->end = newNode;
break;
} else if(p == depand ){
temporary_data = depand->next;
depand->next = newNode;
newNode->next = temporary_data;
if(depand == tab->end;
tab->end = newNode;
break;
}
}
p = p->next;
}while(p->next != NULL);
}
struct node {
char name[10];
int age;
struct node *next;
};
struct table {
struct node *head;
struct node *end;
size_t size;
};
void table_insert(struct table *tab, struct node *newNode, struct node *depand) {
struct node *temporary_data, *p;
p = tab->head;
do{
if (tab->head == NULL) {
tab->head = newNode;
newNode->next = NULL;
tab->end = newNode;
break;
} else {
if (tab->head == depand) {
depand ->next = newNode;
newNode->next = NULL;
if(depand == tab->end;
tab->end = newNode;
break;
} else if(p == depand ){
temporary_data = depand->next;
depand->next = newNode;
newNode->next = temporary_data;
if(depand == tab->end;
tab->end = newNode;
break;
}
}
p = p->next;
}while(p->next != NULL);
}
struct node {
char name[10];
int age;
struct node *next;
};
struct table {
struct node *head;
struct node *end;
size_t size;
};
更多追问追答
追问
如果我要把插入的节点插在head,而后面还有节点,你这里面好像没有
追答
你的问题是插在depand后,所以你不能插在head,而后面还有节点。除非你把问题改成插在depand之前。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询