-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraylist.java
More file actions
82 lines (69 loc) · 1.69 KB
/
Arraylist.java
File metadata and controls
82 lines (69 loc) · 1.69 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import java.util.ArrayList;
/**
* Universidad del Valle de Guatemala
* Algoritmos y Estructura de Datos
* Sección: 10
* 20/08/2015
* Hoja de Trabajo 4
*
*/
/**
*
* La clase Arraylist es una Pila.
* Utiliza datos tipo Integer. Con esta clase se pretende utilizar
* la clase ArrayList y Pila la cual tiene opciones predefinidas que harán
* que se cree un Arraylist que tendrá la forma de una pila
* por los métodos definidos para esta clase. Gracias a esta clase
* se harán operaciones en notación Postfix en Calculadora si es
* seleccionada entre las opciones
*
* @author André Rodas
* @author Rudy Garrido
* @author Yosemite Meléndez
*
* @param <Integer> para recibir datos numéricos
*/
public class Arraylist<E> extends Pila<Integer> {
private ArrayList <Integer> arrayList;
/**
* Este es el constructor de Arraylist y crea un nuevo arraylist
* de la Clase ArrayList
* Crea un Objeto:
* arrayList que será el nuevo ArrayList
* La inicializa y la vacía.
*/
public Arraylist() {
this.arrayList = new ArrayList <Integer>();
arrayList.clear();
}
@Override
public void empty() {
arrayList.clear();
}
@Override
public boolean isEmpty() {
return arrayList.isEmpty();
}
@Override
public int size() {
return arrayList.size();
}
@Override
public Integer pop() throws Exception {
if (arrayList.isEmpty())
throw new Exception("Arraylist vacio!");
else
return arrayList.remove(arrayList.size()-1);
}
@Override
public Integer peek() throws Exception {
if (arrayList.isEmpty())
throw new Exception("ArrayList vacio!");
else
return arrayList.get(arrayList.size()-1);
}
@Override
public void push(Integer x) {
arrayList.add(x);
}
}