栈
查看原帖
栈
1015002
Charles_with_wkc楼主2024/6/3 19:38

不关注,仅供娱乐,违规紫衫

#include<bits/stdc++.h>
using namespace std;
const int N=105;
int t;
string fun_stack_str;
int fun_stack[N],fun_stack_top=0,fun_stack_x;
void fun_stack_push(int x){
	if(fun_stack_top>=N){
		cout<<"栈满!\n";
		return ; 
	}
	fun_stack[++fun_stack_top]=x;
	return ;
}
void fun_stack_pop(){
	if(fun_stack_top==0){
		cout<<"栈空!\n";
		return ;
	}
	fun_stack_top--;
	return ;
}
void fun_stack_size(){
	cout<<"The stack's size is "<<fun_stack_top<<endl;
	return ; 
}
void fun_stack_empty(){
	if(fun_stack_top>0){
		cout<<"The stack isn't empty\n"; 
	}
	else{
		cout<<"The stack is empty\n"; 
	}
	return ;
}
int main(){
	cin>>t;
	while(t--){
		cin>>fun_stack_str;
		if(fun_stack_str=="push"){
			cin>>fun_stack_x;
			fun_stack_push(fun_stack_x);
		}
		else if(fun_stack_str=="pop"){
			fun_stack_pop();
		}
		else if(fun_stack_str=="size"){
			fun_stack_size();
		}
		else if(fun_stack_str=="empty"){
			fun_stack_empty();
		}
	}
	return 0;
}
2024/6/3 19:38
加载中...