-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.java
More file actions
57 lines (49 loc) · 1.32 KB
/
Stack.java
File metadata and controls
57 lines (49 loc) · 1.32 KB
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
package assign06;
import java.util.NoSuchElementException;
/**
* This interface specifies the general behavior of a last-in-first-out (LIFO)
* stack of elements.
*
* @author CS 2420 course staff
* @version February 20, 2025
*
* @param <E> - the type of elements contained in the stack
*/
public interface Stack<E> {
/**
* Removes all of the elements from the stack.
*/
public void clear();
/**
* Answers whether the stack is empty or contains elements.
*
* @return true if the stack contains no elements; false, otherwise.
*/
public boolean isEmpty();
/**
* Returns, but does not remove, the element at the top of the stack.
*
* @return the element at the top of the stack
* @throws NoSuchElementException if the stack is empty
*/
public E peek() throws NoSuchElementException;
/**
* Returns and removes the item at the top of the stack.
*
* @return the element at the top of the stack
* @throws NoSuchElementException if the stack is empty
*/
public E pop() throws NoSuchElementException;
/**
* Adds a given element to the stack, putting it at the top of the stack.
*
* @param element - the element to be added
*/
public void push(E element);
/**
* Gets the number of elements in the stack.
*
* @return the number of elements in the stack
*/
public int size();
}