
写一个读入一个字符串,把它顺序存入一个双向链表,并按逆序输出的程序 (数据结构c语言)
2个回答
展开全部
#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;
}
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;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#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);
}
#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);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询