📄 class1.cs
字号:
using System;
namespace Exam2_10
{
interface CharStackinterface//定义栈的接口
{
char pop();
void initStack();
bool push(char x);
bool empty();
bool full();
}
class CharStack:CharStackinterface//定义栈类,该类实现了栈接口
{
private char []data;
private const int maxsize=100;
private int top;
public CharStack()
{
data=new char[maxsize];
}
public void initStack()
{
top=-1;
}
public bool push(char x)
{
if(!full())
{
data[++top]=x;
return true;
}
else
{
return false;
}
}
public char pop()
{
if(!empty())
{
top--;
return data[top+1];
}
else
return '\0';
}
public bool empty()
{
return top==-1;
}
public bool full()
{
return top==maxsize-1;
}
}
class Class1
{
public static void Main()
{
CharStack s=new CharStack();
s.initStack();
s.push('A');
s.push('B');
System.Console.WriteLine(s.pop());
System.Console.WriteLine(s.pop());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -