链式栈的基数操作



定义栈链
ttypedef struct StackNode
{
  ElemType data; //存放栈的数据
  struct StackNode *next;
}StackNode, *LinkStackPtr;

typedef struct LinkStack
{
	LinkStack top; //top指针
	int count;  //栈元素计数器
};


入栈链
Status Push(LinkStack *s, ElemType e)
{
	LinkStack p = (LinkStack) malloc(sizeof(StackNode));
	p->data =  e;
	p->next = s->top;
	s->top = p;
	s->count ++;
	return Ok;

出栈链
Status Push(LinkStack *s, ElemType e)
{
	LinkStack p = (LinkStack) malloc(sizeof(StackNode));
	p->data =  e;
	p->next = s->top;
	s->top = p;
	s->count ++;
	return Ok;
}



你可能感兴趣的:(栈链)