📄 characterstack.java
字号:
public class CharacterStack {
public int top;
public char stack[] = new char[100];
public void initialize()
{
top=-1;
}
public boolean isFull()throws Exception
{
if(top>=9)
return true;
else
return false;
}
public boolean isEmpty()
{
if(top==-1)
return true;
else
return false;
}
public void push(char c)throws Exception
{
try
{
if(isFull()) throw new StackOverflowException("栈已经满了 !");
else stack[++top]=c;
}
catch(StackOverflowException e)
{
System.out.println("Exception: "+e);
}
}
public char pop()throws Exception
{
try
{
if(isEmpty())throw new StackUnderflowException();
else
return stack[top--];
}
catch(StackUnderflowException e)
{
System.out.println("Exception: "+e);
}
return 0;
}
public int size()
{
return top+1;
}
public boolean isMatching(char temp1, char temp2)
{
if( temp1=='(' && temp2==')' ) return true;
if( temp1=='[' && temp2==']' ) return true;
if( temp1=='{' && temp2=='}' ) return true;
return false;
}
public boolean chack(char b[], int n)throws Exception
{
if(n==1)
return false;
push(b[0]);
for(int i=1;i<n;i++)
{
if( b[i]!=')' && b[i]!= ']' && b[i]!='}')
{
push(b[i]);
}
else if( !(isMatching(pop(),b[i])) ) return false;
}
if(size()!=0)
return false;
else
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -