-
Notifications
You must be signed in to change notification settings - Fork 0
/
StackInterface.java
58 lines (52 loc) · 1.4 KB
/
StackInterface.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
package com.company;
/**
* Interface detailing the methods required for implementing a stack.
*
* DO NOT EDIT THIS FILE!
*
* @author CS 1332 TAs
* @version 1.0
*/
public interface StackInterface<T> {
/**
* The initial capacity of a stack with fixed-size backing storage.
*/
public static final int INITIAL_CAPACITY = 10;
/**
* Return true if this stack contains no elements, false otherwise.
*
* This method should be implemented in O(1) time.
*
* @return true if the stack is empty; false otherwise
*/
boolean isEmpty();
/**
* Pop from the stack.
*
* Removes and returns the top-most element on the stack.
* This method should be implemented in O(1) time.
*
* @return the data from the front of the stack
* @throws java.util.NoSuchElementException if the stack is empty
*/
T pop();
/**
* Push the given data onto the stack.
*
* The given element becomes the top-most element of the stack.
* This method should be implemented in (if array-backed, amortized) O(1)
* time.
*
* @param data the data to add
* @throws IllegalArgumentException if data is null
*/
void push(T data);
/**
* Return the size of the stack.
*
* This method should be implemented in O(1) time.
*
* @return number of items in the stack
*/
int size();
}