//stack
// FiFo
//algoritham
/* 1) create stack classs with attripute of size and storage
add :store the value and increment
remove : remove the value and decrement
*/
/*function Stack() {
this.size = 0;
this.storage = {};
}
Stack.prototype.push = function(data) {
this.storage[this.size] = data;
this.size++;
};
Stack.prototype.pop = function() {
var deletedNode;
if (this.size) {
this.size--;
deletedNode = this.storage[this.size];
delete this.storage[this.size];
}
return deletedNode;
};
var s = new Stack();
s.push("50");
s.push("20");
s.push("10");
s.pop();
console.log(s.storage);*/
// Queue
// FiLo
// create class with Queue and properties for storage and index
// create watch for adding delecting node using index
/*function Queue() {
this.storage = {};
this.addIndex = 1;
this.deleteIndex = 1;
}
Queue.prototype.addQueue = function(data) {
this.storage[this.addIndex] = data;
this.addIndex++;
}
Queue.prototype.removeQueue = function() {
if (this.deleteIndex != this.addIndex) {
delete this.storage[this.deleteIndex];
this.deleteIndex++;
}
}
var s = new Queue();
s.addQueue("50");
s.addQueue("20");
s.addQueue("10");
s.removeQueue();
s.removeQueue();
s.removeQueue();
s.removeQueue();
console.log(s.storage); */
// list
// linked list
// create node with data and next
// create list class with head and size
function Node(data) {
this.data = data;
this.next = null;
}
function LinkedList() {
this.head = null;
this.size = 0;
}
LinkedList.prototype.addNode = function(value) {
var node = new Node(value);
var cNode = this.head;
// if list has one node
if (!cNode) {
this.head = node;
this.size++;
// console.log(this.size,"came ");
return
} else {
while (cNode.next) {
cNode = cNode.next;
}
cNode.next = node;
}
this.size++;
}
LinkedList.prototype.deleNode = function(pos) {
var cNode = this.head;
var prevNode;
var count = 1;
// if list has...
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.