#include "stdio.h"
#include "string.h"
#include "stdlib.h"
//#include <alloc.h>
typedef int ElemType;
/*
创建链表式栈结构体
*/
typedef struct Stack_Node
{
ElemType data;
struct Stack_Node *next;
}stack_node;
/*
初始化栈
*/
stack_node* initStack()
{
struct Stack_Node *top;
top=(struct Stack_Node*)malloc(sizeof(struct Stack_Node));
top->next=NULL;
return top;
}
/*
进栈
*/
stack_node* insertNode(stack_node *p,ElemType e)
{
struct Stack_Node *top;
top=(struct Stack_Node*)malloc(sizeof(struct Stack_Node));
if (!top)
{
printf("apply memory error!
");
return p;
}
top->data=e;
top->next=p->next;
p->next=top;
return p;
}
/*
出栈
*/
stack_node* popNode(stack_node *p)
{
struct Stack_Node *top;
ElemType e;
if (p->next==NULL)
{
printf("stack is empty!
");
return p;
}
top=p->next;
e=top->data;
p->next=top->next;
return p;
}
/*
打印栈中的数据
*/
void print(stack_node *p)
{
struct Stack_Node *top;
top=p->next;
while(top!=NULL)
{
printf("%d",top->data);
top=top->next;
}
}
void main()
{
struct Stack_Node *top;
top=initStack();
int n=1348,i;
while(n!=0)
{
i=n % 8;
insertNode(top,i);
n=n / 8;
}
print(top);
getchar();
}