-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMVector.java
More file actions
78 lines (64 loc) · 1.56 KB
/
MVector.java
File metadata and controls
78 lines (64 loc) · 1.56 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
/**
* Universidad del Valle de Guatemala
* Algoritmos y Estructura de Datos
* Sección: 10
* 20/08/2015
* Hoja de Trabajo 4
*
*/
import java.util.Vector;
/**
*
* La clase MVector y es una Pila.
* Utiliza datos tipo Integer. Con esta clase se pretende utilizar
* la clase Vector y Pila la cual tiene opciones predefinidas que harán
* que se cree un vector de datos 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 MVector <Integer> extends Pila<Integer> {
private Vector <Integer> vector;
/**
* Este es el constructor de MVector y crea un nuevo vector
* de la Clase Vector
* Crea un Objeto:
* vector que será el nuevo vector
* Lo inicializa y la vacía.
*/
public MVector() {
this.vector = new Vector <Integer>();
vector.clear();
}
public void empty() {
vector.clear();
}
public boolean isEmpty() {
return vector.isEmpty();
}
public int size() {
return vector.size();
}
public Integer pop() throws Exception {
if (vector.isEmpty())
throw new Exception("Vector vacio!");
else
return vector.remove(vector.size()-1);
}
public Integer peek() throws Exception {
if (vector.isEmpty())
throw new Exception("Vector vacio!");
else
return vector.lastElement();
}
public void push(Integer x) {
vector.add(x);
}
}