Módulo 4 · Especialización30 min
Estructuras de Datos
Linked List, Stack, Queue, Tree.
Recompensa al completar
Insignia “Data structures” · +30 puntos
Stack (Pila) — LIFO
javascript
class Stack {
constructor() { this.items = []; }
push(item) { this.items.push(item); }
pop() { return this.items.pop(); }
peek() { return this.items[this.items.length - 1]; }
isEmpty() { return this.items.length === 0; }
}Queue (Cola) — FIFO
javascript
class Queue {
constructor() { this.items = []; }
enqueue(item) { this.items.push(item); }
dequeue() { return this.items.shift(); }
front() { return this.items[0]; }
isEmpty() { return this.items.length === 0; }
}Linked List
javascript
class Node {
constructor(valor) {
this.valor = valor;
this.siguiente = null;
}
}Binary Tree
javascript
class TreeNode {
constructor(valor) {
this.valor = valor;
this.izquierdo = null;
this.derecho = null;
}
}?Ejercicio
Implementa una clase Stack con push, pop y peek.
editor.js
1234567
Recompensa al completar
Insignia “Data structures” · +30 puntos