顺序栈

Posted linkmust

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了顺序栈相关的知识,希望对你有一定的参考价值。

#include "stdafx.h"
#include<iostream>

using namespace std;

#define MAXSTACK 10
typedef int StackEntry;

typedef struct node {
    StackEntry entry[MAXSTACK];
    int top;
}SeqStack;


typedef enum Status {
    success, fail, fatal, rangeerror, overflow
}Status;

SeqStack * init_SeqStack() {
    SeqStack *s;
    s = (SeqStack*)malloc(sizeof(SeqStack));
    s->top = -1;
    return s;
}

int Empty_SeqStack(SeqStack s) {
    if (s.top == -1)return 1;
    else return 0;
}

int Push_SeqStack(SeqStack *s, StackEntry elem) {
    if (s->top == MAXSTACK - 1) return 0;
    else {
        s->top++;
        s->entry[s->top] = elem;
        return 1;
    }
}

int Pop_SeqStack(SeqStack *s, StackEntry *elem) {
    if (s->top == -1)return 0;
    else {
        *elem = s->entry[s->top];
        s->top--;
        return 1;
    }
}

StackEntry Top_SeqStack(SeqStack *s) {
    if (s->top == -1)return 0;
    else {
        return  s->entry[s->top];
    }
}

int main() {
    SeqStack * s = init_SeqStack();
    int num;
    for (int i = 0; i < MAXSTACK - 1; i++) {
        cin >> num;
        Push_SeqStack(s, num);
    }
    

    StackEntry   elem;
    Pop_SeqStack(s, &elem);
    cout << elem << endl;
    cout << Top_SeqStack(s) << endl;
    system("pause");
    return EXIT_SUCCESS;
}

 

以上是关于顺序栈的主要内容,如果未能解决你的问题,请参考以下文章

html 将以编程方式附加外部脚本文件的javascript代码片段,并按顺序排列。用于响应式网站,其中ma

考研数据结构模板:顺序表链表栈队列

C++ class实现顺序栈(完整代码)

数据结构--栈(Stack)

数据结构--栈(Stack)

数据结构_顺序栈的代码实践