Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My output is not displaying any help would be appreciated HTML Queue Javascript: var element = document.getElementById(number).value; function Queue() { this.length = 0; this.head =

My output is not displaying any help would be appreciated

HTML

Queue

Javascript:

var element = document.getElementById("number").value;

function Queue() {

this.length = 0; this.head = null; this.tail = null;

this.insert = function(data){ var node = { data: data, next: null, prev: null };

if (this.length == 0) { this.head = node; this.tail = node; } else {

this.tail.next = node; node.prev = this.tail; this.tail = node; }

this.length++; };

this.delete = function(){ if(this.length == 0) { document.getElementById("output").innerHTML = "Queue is empty!"; return null; }

var deletedElement = this.head.data; this.head = this.head.next; this.head.prev = null;

this.length--;

if(this.length == 0) { this.clear(); }

return deletedElement; };

this.deleteByElement = function(element) {

var x=this.head; while(x != null){ if(x.data == element) {

var bef = x.prev; if(bef == null) { this.head = x.next; } else { bef.next = x.next; }

var aft = x.next; if(aft == null) { this.tail = x.prev; } else { aft.prev = x.prev; }

return true; } x = x.next; } return false; }

this.deleteByFactor = function(element) { var deleted=false; var x=this.head; while(x != null){ if(x.data%element==0) { this.deleteByElement(x.data); deleted=true; } x = x.next; } return deleted; }

this.isEmpty = function(){ return this.length == 0; };

this.size = function(){ return this.length; };

this.clear = function(){ this.head = null; this.tail = null; this.length = 0; };

this.print = function(){ var x=this.head; var queue=''; while(x != null){ queue = queue + x.data +","; x = x.next; } return queue; }; }

function createQueue(queue){

var newqueue = new Queue(); var iter=0; var create=2;

document.getElementById("output").innerHTML = "Iteration "+iter+": L1 = "+queue.print()+" Q1 ="+newqueue.print(); while(!queue.isEmpty()){

if(queue.deleteByFactor(create)){ iter++; newqueue.insert(create);

document.getElementById("output").innerHTML = "Iteration "+iter+": L1 = "+queue.print()+" Q1 ="+newqueue.print();

} create++; } }

var queue = new Queue(); for(var i=2;i<=element;i++) queue.insert(i);

createQueue(queue);

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

Recommended Textbook for

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions