-
Notifications
You must be signed in to change notification settings - Fork 303
/
Copy pathStack.java
52 lines (47 loc) · 1.15 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
/**
* The Stack interface represents a last-in-first-out (LIFO) stack of elements.
*/
public interface Stack<E> {
/**
* Returns the number of elements in the stack.
*
* Complexity: O(1)
*
* @return the number of elements in the stack
*/
int size();
/**
* Returns true if the stack is empty, false otherwise.
*
* Complexity: O(1)
*
* @return true if the stack is empty, false otherwise
*/
boolean isEmpty();
/**
* Pushes an element onto the top of the stack.
*
* Complexity: O(1)
*
* @param element the element to be pushed onto the stack
*/
void push(E element);
/**
* Removes and returns the element at the top of the stack.
*
* Complexity: O(1)
*
* @return the element at the top of the stack
* @throws EmptyStackException if the stack is empty
*/
E pop();
/**
* Returns the element at the top of the stack without removing it.
*
* Complexity: O(1)
*
* @return the element at the top of the stack
* @throws EmptyStackException if the stack is empty
*/
E peek();
}