-
Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathStack.java
51 lines (44 loc) · 1.12 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
package com.thealgorithms.datastructures.stacks;
/**
* A generic interface for Stack data structures.
*
* @param <T> the type of elements in this stack
*/
public interface Stack<T> {
/**
* Adds an element to the top of the stack.
*
* @param value The element to add.
*/
void push(T value);
/**
* Removes the element at the top of this stack and returns it.
*
* @return The element popped from the stack.
* @throws IllegalStateException if the stack is empty.
*/
T pop();
/**
* Returns the element at the top of this stack without removing it.
*
* @return The element at the top of this stack.
* @throws IllegalStateException if the stack is empty.
*/
T peek();
/**
* Tests if this stack is empty.
*
* @return {@code true} if this stack is empty; {@code false} otherwise.
*/
boolean isEmpty();
/**
* Returns the size of this stack.
*
* @return The number of elements in this stack.
*/
int size();
/**
* Removes all elements from this stack.
*/
void makeEmpty();
}