Sequentially storing stack implemented

Sequential storage structure that typically consists of a stack of arrays and a top element position variable records.

#define MaxSize //<储存数据元素的最大个数>
typedef struct SNode*Stack;
struct SNode{
	ElementType Data[MaxSize];
	int Top;
};
//(1)入栈
void Push(Stack PtrS, ElementType item)
{
	if(PtrS->Top == MaxSize - 1){
	  print("堆栈满"); return ;
    }else{
      PtrS -> Data[++(PtrS -> Top)] = item;
      return ;
}

} 
//(2)出栈
ElementType Pop(Stack PtrS)
{
	if(PtrS -> Top == -1){
		printf("堆栈空");
		return ERROR;//ERROR是ElementType的特殊值,标志
		             //错误
		
		
}else
	return (PtrS -> Data[(Ptrs -> Top)--]);
}
Published 28 original articles · won praise 3 · Views 1894

Guess you like

Origin blog.csdn.net/qq_44045101/article/details/104066205