#include<iostream>
using namespace std;
class Stack {
public:
int Data[10];
int Top = -1;
};
//入栈
void Push(Stack* PtrS, int item)
{
if (PtrS->Top == 10 - 1)
{
printf("堆栈满");
return;
}
else {
PtrS->Data[++(PtrS->Top)] = item;
return;
}
}
void test01() {
Stack s;
Push(&s, 10);
cout << s.Data[s.Top] << endl;
cout << s.Top << endl;
}
//出栈
int pop(Stack *PtrS)
{
if (PtrS->Top == -1)
{
printf("堆栈空");
return NULL;
}
else {
return(PtrS->Data[(PtrS->Top)--]);
}
}
void test02()
{
Stack s;
Push(&s, 20);
cout << pop(&s) << endl;
cout << s.Top << endl;
}
int main(){
//test01();
test02();
return 0;
}
堆栈的顺序存储实现
最新推荐文章于 2022-11-14 14:30:09 发布