写一个读入一个字符串,把它顺序存入一个双向链表,并按逆序输出的程序 (数据结构c语言)

学了数据结构,可不知道怎么把算法和c语言结合就要做实验了,希望得到帮助... 学了数据结构,可不知道怎么把算法和c语言结合 就要做实验了,希望得到帮助 展开
 我来答
厚土西安巿临潼D0
2011-11-22 · TA获得超过691个赞
知道小有建树答主
回答量:351
采纳率:0%
帮助的人:502万
展开全部
#include "stdio.h"
struct node
{
struct node *front;
char c;
struct node *next;
};
struct node *input(struct node *top);
int main(void)
{
struct node T,*top=&T,*tail=&T,*p=NULL;
T.front=NULL;
T.next=NULL;
T.c='\0';
tail=input(top);
p=tail->front;
while(p!=NULL)
{
printf("%c",p->c);
p=p->front;
}
return 0;

}

struct node *input(struct node *top)
{
int i=0;
struct node *t;
char x;
while((x=getchar())!='\n')
{
top->c=x;

t=(struct node *)malloc(sizeof(struct node));
top->next=t;
t->front=top;
t->next=NULL;
t->c='\0';
top=top->next;
}

return top;
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
xianglanhui
2011-11-22
知道答主
回答量:1
采纳率:0%
帮助的人:1788
展开全部
#include <stdio.h>
#include <malloc.h>
typedef struct Node
{
int data;
struct Node *next;
}Node;

void Creatlist(Node *head,int n)
{
Node *p,*pn;
p=head;
int i;
for(i=1;i<=n;i++)
{
pn=(Node*)malloc(sizeof(Node));
scanf("%d",&pn->data);
pn->next=p->next;
p->next=pn;
}
}

void Printlist(Node *head)
{
Node *p;
p=head;
p=p->next;
while(p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
}

void main()
{
Node *s;
s->next=NULL;
int n;
scanf("%d",&n);
Creatlist(s,n);
Printlist(s);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式