Skip to content

Commit a941ef6

Browse files
committed
creando y usando la clase cola
1 parent fd241a7 commit a941ef6

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

Roadmap/08 - CLASES/javascript/Pancratzia.js

+33-2
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,41 @@ class Pila {
8585
}
8686
}
8787

88-
8988
const pila = new Pila();
9089
pila.push("hola");
9190
pila.push("mundo");
9291
pila.push("!");
9392
console.log(pila.print());
94-
console.log(pila.size());
93+
console.log(pila.size());
94+
95+
class Cola {
96+
constructor() {
97+
this.cola = [];
98+
}
99+
100+
encolar(elemento) {
101+
this.cola.push(elemento);
102+
}
103+
104+
desencolar() {
105+
this.cola.shift();
106+
}
107+
108+
size() {
109+
return this.cola.length;
110+
}
111+
112+
print() {
113+
return this.cola;
114+
}
115+
}
116+
117+
const cola = new Cola();
118+
cola.encolar("hola");
119+
cola.encolar("mundo");
120+
cola.encolar("!");
121+
cola.encolar("Soy");
122+
cola.encolar("una");
123+
cola.encolar("cola");
124+
console.log(cola.print());
125+
console.log(cola.size());

0 commit comments

Comments
 (0)