#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!\n");
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!\n");
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();
}