-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdvCSStack.java
43 lines (34 loc) · 918 Bytes
/
AdvCSStack.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
/****************************
* AdvCSSstack.java Author: Robert Walker
*
* Purpose: Implementation of generic type stack.
*****************************/
import java.util.ArrayList;
public class AdvCSStack<T> implements GenStackInterface<T> {
//Constructor
public AdvCSStack() {
}
ArrayList<T> stackPrep = new ArrayList <>(); //Stack ArrayList
// Adds item T to ArrayList
public void push(T t) {
stackPrep.add(t);
}
// Remove and return top item in the stack
public T pop() {
//T t = stackPrep.get(stackPrep.size() -1);
return stackPrep.remove((stackPrep.size()-1));
//return t;
}
// Return top item in the stack
public T peek() {
return stackPrep.get(stackPrep.size()-1);
}
//Returns true or false if stack is empty
public boolean isEmpty() {
return stackPrep.isEmpty();
}
public String toString() {
String output = stackPrep.size()-1 + " ";
return output;
}
}