顺序栈的初始化,进栈,出栈,销毁栈

    科技2024-07-15  65

    #include <iostream> using namespace std; typedef int ElemType; #define MaxSize 100 typedef struct { ElemType date[MaxSize]; int top; }SqStack; void SqstackInit(SqStack*&s)//栈的初始化 { s = (SqStack*)malloc(sizeof(SqStack)); s->top = -1; } bool pushSqstack(SqStack*&s, ElemType e)//进栈 { if (s->top == MaxSize-1) return false; s->date[s->top + 1] = e; s->top++; return true; } bool pushOutStstack(SqStack*&s, ElemType &e)//出栈 { if (s->top == -1) return false; s->date[s->top + 1] = e; s->top--; return true; } void destroyStstack(SqStack*&s)//销毁栈 { free(s); } int main() { SqStack *s; int i = 4,e; SqstackInit(s); pushSqstack(s,i); pushOutStstack(s, e); destroyStstack(s); }
    Processed: 0.009, SQL: 8