#include "Stdio.h"
#include "Conio.h"
typedef struct Node //定义栈
{
int data;
struct Node *next;
}Node,*LKStack;
void inistack(LKStack *s) //初始化栈
{
*s=(Node*)malloc(sizeof(Node));
(*s)->next=NULL;
}
int isEmpty(LKStack s) //判空
{
return s->next==NULL;
}
int push(LKStack s,int e) 入栈
{
Node *r;
r=(Node*)malloc(sizeof(Node));
if(r==NULL) return 0;
r->data=e;
r->next=s->next;
s->next=r;
}
int pop(LKStack s,int *e) //出栈
{
Node *r;
if(isEmpty(s)) return 0;
r=s->next;
s->next=r->next;
*e=r->data;
free(r);
}
int gettop(LKStack s,int *e)//取栈顶元素
{
if(isEmpty(s)) return 0;
*e=s->next->data;
}
void main(void) //把八进制1357转换成十进制数
{
int a=1357;
int b,e;
Node *s;
while(a)
{
b=a%8;
a=a/8;
push(s,b);
}
while(isEmpty(s))
{
pop(s,e);
printf("%d",e);
}
}
不显示结果,是怎么回事啊 ?大虾们谢谢了 !