Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Utilize the doubly linked list code shown below as a base for the stack * * Please post the HTML and Javascript - must be

Utilize the doubly linked list code shown below as a base for the stack**Please post the HTML and Javascript - must be able to run in JS Fiddle (jsfiddle.net)- when using jsfiddle make sure to select "no wrap in body" or "no wrap in head" under the javascript settings******Must be built using a list, not an array*** Implement a Stack in Javascript (you will turn in a link to your program in JSFiddle). Do not use an array as the stack or in the implementation of the stack. Repeat - You MUST implement the Stack (start with your linked list) without the use of an array.. You will build a Stack Computer from your stack. When a number is entered it goes onto the top of the stack. When an operation is entered, the previous 2 numbers are operated on by the operation and the result is pushed onto the top of the stack. This is how an RPN calculator. For example 2[enter]25[enter]52*[enter]*52-> collapses to 10 would leave at 10 at the top of the stack. The program should use a simple input box, either a text field or prompt and display the contents of the Stack. let list = null;
function createList(){
let value = document.getElementById("LinkName").value;
list = new List(value);
document.getElementById("demo").innerHTML = list.print();
}
function addNode(){
let value = document.getElementById("LinkName").value;
list.addNode(value,list.last);
document.getElementById("demo").innerHTML = list.print();
}
function Node(_value, _last){
this.value =_value;
this.last =_last;
this.next = null;
return this;
}
Node.prototype.asString = function (){
return "-->Node Value: "+ this.value +"";
}
function List(_value){
this.length =1;
this.head = new Node(_value, null);
this.last = this.head;
}
List.prototype.addNode = function (_value,_last){
let node = new Node(_value, _last);
if (this.length){
this.last.next = node;
node.last = this.last;
this.last = node;
} else {
this.head = node;
this.last = node;
}
this.length++;
}
List.prototype.print = function (){
let s ="";
let n = this.head;
while (n != null){
s += n.asString();
n = n.next;
}
return s;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Create an Executive Summary

Answered: 1 week ago

Question

2. What, according to Sergey, was strange at this meeting?

Answered: 1 week ago