<html>
<head>
</head>
<body>
<strong>Please enter a number greater than "2" to begin our journey through the Sieve of Eratosthenes</strong>
<br><br>
<input type = textbox id = input value = 2>
<br>
<br>
<input type = button id = enqueue onclick = enq() value = "Enqueue">
<br>
<!--<input type = button id = enqueue onclick = prn() value = "Print">-->
<div id = "out">
</div>
<input type = button id = sieve onclick = sieve() value = "Sieve">
</body>
</html>
JavaScript
//captains log: Update number 277... its time to hit that set as base button... still unable to retrieve the second element in q1. possible reasons"
// 1) Psycosis
// 2) Initial pickup of q1.head and subsequence q1.head = q1.head.next may be the problem
// 3) Piss poor programmer?
var q1 = new Queue();
var q2 = new Queue();
function Queue() {
this.head = null;
this.tail = null;
this.length = 0;
}
function Node() {
this.content = null;
this.next = null;
this.prev = null;
}
Queue.prototype.nq = function(data){
var node = new Node();
node.content = data;
if (this.tail == null){
this.length = 0;
this.head = node;
this.tail = node;
this.length ++;
console.log("created first node");
return this;
}
else{
this.tail.next = node;
node.prev = this.tail
this.tail = node;
this.length ++;
return this;
}
}
Queue.prototype.print = function (){
var traveler = this.head;
var s = '';
while (traveler){
s += traveler.content +', ' ;
traveler= traveler.next;
}
return s;
}
Queue.prototype.dq = function (decom_node) {
// var penance = new Node();
if (decom_node.next == null){
decom_node.prev.next = null;
this.tail = decom_node.prev;
}
else if(decom_node.prev==null){
decom_node = decom_node.next;
decom_node.next.prev = null;
return decom_node;
}
else{
decom_node.prev.next = decom_node.next;
decom_node.next.prev = decom_node.prev;
return decom_node.next;
//console.log(penance);
//decom_node = null;
}
}
Queue.prototype.clear = function(){
this.head = null;
this.tail = null;
this.lenght = 0;
}
function sieve() {
var traveler = new Node(); traveler = q1.head;
var second_traveler = new Node();
var i = 0;
var q1_s = '';
var q2_s= '';
var final_form_string ='';
if(q2.head == null){
q2.nq(traveler.content);
q1.head = traveler.next;
}
second_traveler = q2.head;
while(i <...
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.