var q1 = new List();
var q2 = new List();
// When button is clicked createQueue() is called
function createQueue() {
var x;
var y;
var value = parseInt(document.getElementById("QueueSize").value);
//create the queue
for (let i = 2; i <= value; i++) {
q1.enqueue(i);
}
var display = "";
var display2 = "";
var l = q1.length;
for (let i = 2; i <= l; i++) {
display += "Iteration " + i + " = " + q1.print() + "<br/>";
display2 += "Iteration " + i + " = " + q2.print() + "<br/>";
var d = q1.length;
x = q1.dequeue();
document.getElementById("demo").innerHTML = display;
document.getElementById("demo2").innerHTML = display2;
q2.enqueue(x);
//document.getElementById("demo2").innerHTML = q2.print();
//looping through q1: Dequeue Q1, assign that value to
// if y % by x does not = zero(in other words, if it is divisible by x we are getting rid of it. Otherwise insert it back into Q1)
for (let e = 2; e <= d; e++) {
y = q1.dequeue();
if (y % x !== 0) {
q1.enqueue(y);
}
}
//document.getElementById("demo").innerHTML = "Iteration " + i + ": " + " Q1 =" + q1.print();
// document.getElementById("demo2").innerHTML = "Iteration " + i + ": " + " Q2 =" + q2.print();
}
}
// Define the link object
function Node(_value, _last) {
this.value = _value; // The value stored
this.last = _last; // A pointer to the previous link
this.next = null; // a pointer to the next link
return this; // returns the created node
}
Node.prototype.asString = function() {
return this.value + " "; //+ "<br/>";
};
// Define the List object
function List(_value) { // We will define the list with the first link defined
this.length = 0;
this.head = null; // Pointer TO the head is null
this.last = this.head; // When created - head and last are the same.
}
List.prototype.enqueue = function(value) {
let node = new Node(value);
let current;
if (this.head == null) {
this.head =...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.