大佬,又是我。求帮助。老师说要用栈或者队列可以很简单,但是我完全不懂。。。。。

360U3188835312 |浏览892次
收藏|2020/03/22 09:13

满意回答

2020/03/22 09:20

#include <stdio.h>#include <stdlib.h>struct LB {int number;LB* last_p;LB* next_p;};void creat(LB *head_p,LB *p,int number) {if (!number) {p->next_p = head_p;//首尾相连head_p->last_p = p;return;}LB *pp = (LB*)malloc(sizeof(LB));p->next_p = pp;pp->last_p = p;creat(head_p, pp, number - 1);}int main(){int num;//长度LB *bg=NULL;//双向链表头LB* del_p=NULL;//该被删除的链表地址scanf("%d", &num);bg = (LB*)malloc(sizeof(LB)*num);//构建链表头creat(bg, bg, num - 1);//构建首尾相连的双向链表for (int i = 0; i < num; ++i) {scanf("%d", &(bg->number));//获取数字bg = bg->next_p;}while (bg != NULL) {printf("%d ", bg->number);del_p = bg;bg->last_p->next_p = bg->next_p;//重构链表顺序bg->next_p->last_p = bg->last_p;bg = bg->next_p->next_p;//跳过一个,相当于把这一个放在最后if (bg == del_p) bg = NULL;free(del_p);//消除被排除的那一个元素del_p = NULL;}return 0;}

蹭蹭df

其他回答(0)
0人关注该问题
+1

 加载中...