| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 402 人关注过本帖
标题:[分享]一个反向输出出入的程序
只看楼主 加入收藏
gxppa2006
Rank: 1
等 级:新手上路
帖 子:178
专家分:0
注 册:2007-2-27
收藏
 问题点数:0 回复次数:2 
[分享]一个反向输出出入的程序
#include <stdio.h>
#include <malloc.h>
#define NULL 0
typedef struct getchar /*difine a struct used to linklist*/
{
char data;
struct getchar *next;
}node;
node *creat(void) /*define a function used to order print*/
{
node *head,*p,*s;
char x;
int cycle=1;
head=(node *)malloc(sizeof(node));
p=head;
while(cycle)
{
scanf("%c",&x);
if(x!='0')
{
s=(node *)malloc(sizeof(node));
s->data=x;
p->next=s;
p=s;
}
else
cycle=0;
}
p->next=NULL;
p=head;
head=head->next;
free(p);
return head;
}
node *creatback(void) /*define a function used to reverse order print*/
{
node *back,*p;
char x;
int cycle=1;
back=(node *)malloc(sizeof(node));
back->data=NULL;
back->next=NULL;
while(cycle)
{
scanf("%c",&x);
if(x!='0')
{
p=(node *)malloc(sizeof(node));
p->data=x;
p->next=back;
back=p;
}
else
cycle=0;
}
free(p);
return back;
}
int main() /*function main*/
{
node *h,*he;
printf("Please input a string,ends with 0:\n");
h=creat();
printf("order:\n");
while(h!=NULL)
{
printf("%c",h->data);
h=h->next;
}
printf("\n");
printf("Please input a string,ends with 0:\n");
he=creatback();
printf("reverse order:\n");
while(he!=NULL)
{
printf("%c",he->data);
he=he->next;
}
printf("\nOVer!");
getch();
return 0;
}
大家给看看还有没有更好的方法!
搜索更多相关主题的帖子: 输出 分享 
2007-04-18 13:11
lhhsoft
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-4-14
收藏
得分:0 
看不懂 ......
请你用中文注释下好么?

无论你在那里,我离你只有一转身的距离.
2007-04-18 13:51
pinglideyu
Rank: 3Rank: 3
来 自:武汉工程大学
等 级:论坛游侠
威 望:1
帖 子:735
专家分:140
注 册:2007-1-7
收藏
得分:0 
顺序输出可以用一般线型链表,反序输入可以用到栈。
估计楼主是这样的吧。

~~我的明天我知道~~
2007-04-18 15:07
快速回复:[分享]一个反向输出出入的程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014562 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved