用数组实现栈 Array implementation of stacks

来源:互联网 发布:苹果电脑装cad软件 编辑:程序博客网 时间:2024/04/30 00:45
#include <iostream>using namespace std;#define MAXSIZE 4int A[MAXSIZE];int top = -1;void Push(int x){if(top == MAXSIZE-1)return;A[++top] = x;}void Pop(){if(-1 != top)top--;}int Top(){if(-1 != top)return A[top];}void PrintStack(){for(int i = 0; i <= top; i++)cout << A[i] <<" ";cout << endl;}

0 0