Stack-array based implementation【1月17日学习笔记】

点击查看代码
//Stack-array based implementation
#include<iostream>
using namespace std;
#define MAX_SIZE 101
int A[MAX_SIZE];//globle
int top = -1;//globle

void push(int x) {
	if (top == MAX_SIZE - 1) {
		cout << "error:stack overflow" << endl;
		return;
	}	
	A[++top] = x;
}

void pop() {
	if(top ==- 1) {
		cout << "error" << endl;
		return;
	}
	top--;
}

void print() {
	for (int i = 0; i <= top; i++)  cout << A[i] << " ";
	cout << endl;
}

int IsEmpty()
{
	if (top == -1) return 1;
	return 0;
}
 
int Top() {
	return A[top];
}
int main() {
	push(2); print();
	push(5); print();
	push(10); print();
	pop(); print();
	push(12); print();

}
posted @   bituion  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示