?? 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 + -