C语言使用头插法简历双向链表,并实现对称输出

//比如输入的是abcd,输出应该是dcbabcd

#include
#include

struct Clist{
char data;
struct Clist *next;
struct Clist *pre;
};
typedef struct Clist *List;

void create(List &L){
L = (Clist*)malloc(sizeof(Clist));
L->next = NULL;
L->pre = NULL;
char ch;
for(int i = 0;i scanf("%c",&ch);
Clist *q = (Clist*)malloc(sizeof(Clist));
q->data = ch;
q->next = L->next;
L->next->pre = q;
L->next = q;
q->pre = L;
}
}

void print(List &L){
Clist *s = L->next;
while(s->next){
printf("%c ",s->data);
s=s->next;

}
while(s->pre){
    printf("%c ",s->data);
    s=s->pre;
} 

}

int main(){
Clist *head;
create(head);
print(head);
}

查看全部
weixin_40214808
山-东-北-京
2019/03/21 20:56
  • c语言
  • 点赞
  • 收藏
  • 已关闭
    私信
满意答案
查看全部

1个回复