// Define the link object
function Link(_id, _value, _next) {
this.id = _id; // The id of the current link
this.value = _value; // The value stored
this.next = _next; // a pointer to the next link, this is 0 if it is the last link in the chain
}
Link.prototype.theScribe = function () {
return "" + this.value +
" --Location: " + this.id +
" - Points To: " + this.next + "<br/>";
};
// Define the Chain object
function Chain(_firstValue) { // We will define the chain with the first link defined
this.length = 1;
// I like to keep track of the first link, not really necessary
this.head = new Link(1, _firstValue, null);
// I need a place to store this links - an array will work fine and is pretty much one of the few options you have in JS
this.linkStorage = [];
// Oh yea - since we aren't creating an empty Chain - let's fill in that first value
this.linkStorage.push(this.head);
}
Chain.prototype.lastLink = function () {
// A function to find the last link in the chain
return this.linkStorage[this.length - 1];
};
Chain.prototype.Finder = function(eyeDee){
for(var i=0; i < this.length; i++){
if(eyeDee == this.linkStorage[i].id){
return this.linkStorage[i];
}
}
};
Chain.prototype.Push = function (_linkValue) {
// A function to add a link to the chain
this.length++;
var Zelda = new Link(this.length, _linkValue, null);
this.linkStorage.push(Zelda);
this.linkStorage[this.length - 2].next = this.length;
console.log("Pushed value: " + Zelda.value);
return Zelda;
};
Chain.prototype.Pop = function (_linkValue) {
// alert(this.head.value);
var hold = this.head;
var thenext = this.Finder(this.head.next); //set thenext to be the NODE with ID that head points to
this.head = thenext;
console.log("the next: " + thenext.value + " " + thenext.id );
console.log("Popped value: " + hold.value);
return...
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.