欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

The Sqstack for Sequential stack (Continuous updates) | Data

程序员文章站 2022-04-25 19:30:28
...

The Sqstack for Sequential stack | Data

The code in Data book (5th Edition) from the 81 page to 82 page

Continuous updates

#define MaxSize 50
typedef int ElemType;

typedef struct{
    ElemType data[MaxSize];
    int top;
} SqStack;

//Initialization SqStack
void InitStack(SqStack *&s){  
    s=(SqStack *)malloc(sizeof(SqStack));
    s->top=-1;
}

//Destroyed Sqstack
void DestroyStack(SqStack *&s){
    free(s);
}

//Determine if the stack is empty
bool StackEmpty(SqStack *s){
    return(s->top==-1);
}

//Into the stack
bool Push(SqStack *&s, ElemType e){  
    if (s->top==MaxSize-1){
        return false;
    }
    s->top++;
    s->data[s->top]=e;
    return true;
}

//Out stack
bool Pop(SqStack *&s, ElemType &e){  
	if (s->top==-1)
	return false;
	e=s->data[s->top];
	s->top--;
	return true;
}

//Top element of the stack
bool GetTop(SqStack *s, ElemType &e){
    if (s->top==-1)
        return false;
    e=s->data[s->top];
    return true;
}

如有侵权,请联系作者删除

相关标签: Data

上一篇: fetch异常状态处理

下一篇: fetch