Implement pushing to reverse polish stack

Co-Authored-By: td1223
This commit is contained in:
Gleb Koval 2024-11-05 16:47:35 +00:00
parent 9f5a89a63f
commit bdd06f9252
Signed by: cyclane
GPG Key ID: 15E168A8B332382C
2 changed files with 17 additions and 1 deletions

View File

@ -1,7 +1,15 @@
package ic.doc;
import java.util.Stack;
public class ReversePolishStack {
private final Stack<IntOperator> stack = new Stack<>();
public int getSize() {
return 0;
return stack.size();
}
public void push(IntOperator intOperator) {
stack.push(intOperator);
}
}

View File

@ -12,4 +12,12 @@ public class ReversePolishStackTest {
public void reversePolishStackEmptyInitially() {
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));
}
}