其他分享
首页 > 其他分享> > 数据结构-栈的链式存储

数据结构-栈的链式存储

作者:互联网

链栈的实现 

# include<stdio.h>

# define OK 1
# define ERROR 0
# define TRUE 1
# define FALSE 0

typedef int Status;
typedef int SElemType;

typedef struct StackNode{
	SElemType data;
	struct StackNode *next;
}StackNode,*LinkStack; 


// 1、栈的初始化
Status InitLinkStack(LinkStack &S){
	S = NULL;
	return OK;
} 

// 2、链栈是否为空
Status LinkStackEmpty(LinkStack &S){
	if(S == NULL){
		return TRUE;
	}else{
		return FALSE;
	}
} 

// 3、 链栈的入栈
Status Push(LinkStack &S,SElemType e){
	StackNode *p;
	p = new StackNode;
	p->data = e;
	p->next = S;
	S = p;
	return OK;
} 

// 4、链栈的出栈
Status Pop(LinkStack &S,SElemType e){
	StackNode *p;
	if(S == NULL){
		return ERROR;
	}
	e = S->data;
	p = S;
	S = S->next;
	delete p;
	return OK;
} 

// 5、取栈顶元素
SElemType GetTop(LinkStack S){
	if(S != NULL){
		return S->data;
	}
}
 

int main(){
	LinkStack S;
	InitLinkStack(S);
	return 0;
} 

标签:Status,LinkStack,存储,SElemType,return,NULL,StackNode,链式,数据结构
来源: https://blog.csdn.net/XUN__MLF/article/details/123146069