Merge pull request #139 from GrammaTech/intstackget

Add int size() and int get(int index) methods to IntStack.
This commit is contained in:
Julian Dolby 2017-03-09 08:50:03 -05:00 committed by GitHub
commit 3be77aeb3b

View File

@ -59,4 +59,21 @@ public class IntStack {
return top == -1;
}
/**
* @return the number of elements in the stack.
*/
public int size() {
return top + 1;
}
/**
* @return the ith int from the bottom of the stack
*/
public int get(int i) {
if (i < 0 || i > top) {
throw new IndexOutOfBoundsException();
}
return state[i];
}
}