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);
}

1个回答

for(int i = 0;i scanf("%c",&ch);
这是什么鬼?建议你从最基本的学起。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问