-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlockStack.java
61 lines (54 loc) · 1.31 KB
/
BlockStack.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package OrderOfComplexityCalculator;
/**
* Ritesh Sunil Chavan
*/
import java.util.EmptyStackException;
import java.util.Stack;
/**
* This class stores the block of code in the stack
*/
public class BlockStack {
private Stack<CodeBlock> stack = new Stack<>();
/**
* This method pushes the block of code into the stack
* @param block
*/
public void push(CodeBlock block) {
if(stack == null)
throw new EmptyStackException();
else
stack.push(block);
}
/**
* This method pops the block of code from the stack
* @return
*/
public CodeBlock pop() {
if(isEmpty())
throw new EmptyStackException();
return stack.pop();
}
/**
* This methods returns the topmost code block in the stack
* @return topmost code block
*/
public CodeBlock peek() {
if(isEmpty())
throw new EmptyStackException();
return stack.peek();
}
/**
* This method returns the size of the stack
* @return size of the stack
*/
public int size() {
return stack.size();
}
/**
* This method checks whether a stack is empty or not
* @return boolean value of empty stackgg
*/
public boolean isEmpty() {
return stack.isEmpty();
}
}