?? mod9ans.lst
字號:
listing 1
// An exception for stack-full errors.
class StackFullException extends Exception {
int size;
StackFullException(int s) { size = s; }
public String toString() {
return "\nStack is full. Maximum size is " +
size;
}
}
// An exception for stack-empty errors.
class StackEmptyException extends Exception {
public String toString() {
return "\nStack is empty.";
}
}
// A stack class for characters.
class Stack {
private char stck[]; // this array holds the stack
private int tos; // top of stack
// Construct an empty Stack given its size.
Stack(int size) {
stck = new char[size]; // allocate memory for stack
tos = 0;
}
// Construct a Stack from a Stack.
Stack(Stack ob) {
tos = ob.tos;
stck = new char[ob.stck.length];
// copy elements
for(int i=0; i < tos; i++)
stck[i] = ob.stck[i];
}
// Construct a stack with initial values.
Stack(char a[]) {
stck = new char[a.length];
for(int i = 0; i < a.length; i++) {
try {
push(a[i]);
}
catch(StackFullException exc) {
System.out.println(exc);
}
}
}
// Push characters onto the stack.
void push(char ch) throws StackFullException {
if(tos==stck.length)
throw new StackFullException(stck.length);
stck[tos] = ch;
tos++;
}
// Pop a character from the stack.
char pop() throws StackEmptyException {
if(tos==0)
throw new StackEmptyException();
tos--;
return stck[tos];
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -