-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStack.java
58 lines (53 loc) · 1.62 KB
/
Stack.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
/**
* An implementation of a stack, a data structure of type LIFO (Last
* In, First Out).
*
* Classes implementing this interface must use a {@see List} as the
* underlying data structure to store the elements on the stack.
*
* Not all operations on a stack will always be successful. For
* example, a programmer may try to pop an element from an empty
* stack. Since we hace not covered exceptions yet, we need another
* mechanism to report errors. In order to do that, methods of this
* list will return a {@see ReturnObject} that will contain either an
* object or an error value of the right kind (as defined in {@see
* ErrorMessage}).
*
* @author PiJ
*/
public interface Stack {
/**
* Returns true if the stack is empty, false otherwise.
*
* @return true if the stack is empty, false otherwise.
*/
public boolean isEmpty();
/**
* Returns the number of items currently in the stack.
*
* @return the number of items currently in the stack
*/
public int size();
/**
* Adds an element at the top of the stack.
*
* @param item the new item to be added
*/
public void push(Object item);
/**
* Returns the element at the top of the stack. The stack is
* left unchanged.
*
* @return If stack is not empty, the item on the top is returned. If the
* stack is empty, an appropriate error.
*/
public ReturnObject top();
/**
* Returns the element at the top of the stack. The element is
* removed frmo the stack.
*
* @return If stack is not empty, the item on the top is returned. If the
* stack is empty, an appropriate error.
*/
public ReturnObject pop();
}