-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdvCSSSeanStack.java
71 lines (55 loc) · 1.23 KB
/
AdvCSSSeanStack.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
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.util.ArrayList;
public class AdvCSStack<T> implements GenStackInterface<T> {
// Shayan Daijavad Implemented Stack from GenStackInterface 8/22/19
private ArrayList<T> list;
// Constructs a stack
public AdvCSStack()
{
list = new ArrayList<T>();
}
// Adds to stack
public void push(T y)
{
list.add(y);
}
// Removes top element from stack
public T pop()
{
return list.remove(list.size() - 1);
}
// Looks at top element
public T peek()
{
return list.get(list.size() - 1);
}
// Checks if stack is empty
public boolean isEmpty()
{
if(list.size() == 0)
{
return true;
}
else
return false;
}
public AdvCSStack copy()
{
AdvCSStack<T> copy = new AdvCSStack<T>();
AdvCSStack<T> copytwo = new AdvCSStack<T>();
T x;
while (!this.isEmpty())
{
copy.push(this.pop());
}
while (!copy.isEmpty())
{
x = copy.pop();
this.push(x);
copytwo.push(x);
}
return copytwo;
}
public String toString() {
return list.toString();
}
}