Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

193
Vistas
¿Cómo implemento operaciones en una lista apilada?

Actualmente estoy trabajando en la implementación de una calculadora RPN en una pila. Los números ingresan bien en la pila, sin embargo, al intentar realizar operaciones dentro de la pila, parece que hay un contratiempo en alguna parte.

Por ejemplo; al empujar 5 y 6 en la pila, la salida es 5, 6, . Sin embargo, al ingresar + en la pila, regresa con 5, [objeto Objeto][objeto Objeto], en lugar de 5, 11, . ¿Cómo haría para implementar operaciones futuras correctamente para trabajar dentro de la pila y su contenido?

 var Node = function(_content) { this.next = null; this.last = null; this.content = _content; }; var Stack = function() { this.top = null; this.bottom = null; this.push = function(_content) { if (this.bottom == null) { this.bottom = new Node(_content); this.top = this.bottom; return this; } var myNode = new Node(_content); myNode.last = this.top; this.top.next = myNode; this.top = myNode } this.pop = function() { if (this.bottom == null) { alert("The stack is empty") return null } if (this.bottom == this.top) { this.top = this.bottom this.top.last = null return this.top } var testStack = this.top this.top = this.top.last this.top.next = null return testStack } this.toString = function() { var myString = "" var node = this.bottom while (node != null) { myString += node.content + ", " node = node.next; } return myString } } function deleteScreen() { var n = "" document.getElementById("value").value = "" } var stack = new Stack() var x var y var z var result var input function push() { input = document.getElementById("value").value if (input === "" || input === " ") { alert("Please enter a number!") } stack.push(input) document.getElementById('output').innerHTML = stack.toString(); deleteScreen() if (input == '+') { var x = stack.pop() var y = stack.pop() stack.push(x + y) document.getElementById('output').innerHTML = stack.toString(); } };
 <input style="width: 100px" type="textbox" id='value' /> <input type="button" id="assign" value="Insert Number Into Stack" onclick="push()" /> <p id="output"> </p>

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda