建立单链表时输入链表数据(字符数据)以‘#’号结束。
#include
#include
#define M 20
typedef struct
{
char data[M];
int top;
}SeqStack;
typedef struct lnode
{
char data;
struct lnode*next;
}LNode,*LinkList;
SeqStack*Init_SeqStack()
{
SeqStack*s;
s=(SeqStack*)malloc(sizeof(SeqStack));
s->top=-1;
return s;
}
int Push_SeqStack(SeqStack*s,char x)
{
if(s->top==M-1)
return 0;
else
{
s->top++;
s->data[s->top]=x;
return 1;
}
}
int Empty_SeqStack(SeqStack*s)
{
if(s->top==-1)
return 1;
else return 0;
}
int Pop_SeqStack(SeqStack*s,char&x)
{
if(Empty_SeqStack(s))
return 0;
else{
x=s->data[s->top];
return 1;
}
}
LinkList Creat_LinkList()
{
LinkList L;
L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
return L;
}
int main()
{
char x;
LinkList L;
LNode*s,*r;
SeqStack*S;
S=Init_SeqStack();
L=Creat_LinkList();
r=L;
while(1)
{
s=(LinkList)malloc(sizeof(LNode));
scanf("%c",&(s->data));
if(s->data=='#')
{
break;
}
r->next=s;
r=s;
}
r->next=NULL;
s=L;
while(s->next!=NULL)
{
s=s->next;
Push_SeqStack(S,s->data);
}
s=L;
while(!Empty_SeqStack(S))
{ s=s->next;
Pop_SeqStack(S,s->data);
}
s=L;
while(s->next!=NULL)
{
s=s->next;
printf("%c ",s->data);
}
}
http://blog.sina.com.cn/s/blog_4ad9dfe60100xy9c.html
http://zhidao.baidu.com/link?url=HrjuqKWePmt122qaM678rozMrnINMuh7rZdjAkyXeOtMFm4zfEFzeFe8VPMS1SMcu2ANON51CQkhT1oXcTstca
http://blog.sina.com.cn/s/blog_4ad9dfe60100xy9c.html