Implement pushing to reverse polish stack
Co-Authored-By: td1223
This commit is contained in:
parent
9f5a89a63f
commit
bdd06f9252
|
@ -1,7 +1,15 @@
|
||||||
package ic.doc;
|
package ic.doc;
|
||||||
|
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
public class ReversePolishStack {
|
public class ReversePolishStack {
|
||||||
|
private final Stack<IntOperator> stack = new Stack<>();
|
||||||
|
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
return 0;
|
return stack.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void push(IntOperator intOperator) {
|
||||||
|
stack.push(intOperator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,4 +12,12 @@ public class ReversePolishStackTest {
|
||||||
public void reversePolishStackEmptyInitially() {
|
public void reversePolishStackEmptyInitially() {
|
||||||
assertThat(reversePolishStack.getSize(), is(0));
|
assertThat(reversePolishStack.getSize(), is(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void canPushToReversePolishStack() {
|
||||||
|
reversePolishStack.push(new IntOperator(0, args -> 1));
|
||||||
|
assertThat(reversePolishStack.getSize(), is(1));
|
||||||
|
reversePolishStack.push(new IntOperator(0, args -> 2));
|
||||||
|
assertThat(reversePolishStack.getSize(), is(2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue