typedef int ElemType;
/* 节点的类型(包括头节点) */
typedef struct Node{
ElemType elem;
struct Node *next;
}SNode;
/* 初始化,头节点 */
InitStack(SNode* pS)
{
pS->next=NULL;
}
/* 入栈:在头节点之后插入一个新节点 */
Push(SNode* pS,ElemType e)
{
SNode* node;
node = (SNode*)malloc(sizeof(SNode));
node->elem = e;
node->next = pS->next;
pS->next = node;
}
int Pop(SNode* pS,ElemType* pe)
{
SNode* node;
if (pS->next==NULL){
return 0;
}
*pe = pS->next->elem;
node=pS->next;
pS->next=node->next;
free(node);
return 1;
}
阅读(1058) | 评论(0) | 转发(0) |