首页 > 代码库 > 栈的顺序存储和基本实现

栈的顺序存储和基本实现

#include<iostream>#include<cstring>#include<cstdlib>#define maxsize 1000using namespace std;//顺序结构typedef struct {    int data[maxsize];    int top;}SqStack;//初始化栈void initStack(SqStack *&s){    s = new SqStack;    s->top = -1;//空栈}void Clearstack(SqStack *&s){    delete s;}//求栈的长度int StackLength(SqStack *s){    return (s->top+1);}//判断栈是否为空int StackEmpty(SqStack *s){    return (s->top == -1);}//进栈int push(SqStack *&s,int e){    if (s->top == maxsize - 1)//栈满的情况,栈上溢出        return 0;    s->top++;    s->data[s->top] = e;//将e插进栈顶    return 1;}//出栈int  pop(SqStack *&s,int e){    if (s->top == -1)//空栈情况,栈下溢出        return 0;    e= s->data[s->top];    s->top--;    return 1;}

 

栈的顺序存储和基本实现