Skip to content

Instantly share code, notes, and snippets.

@marijer
marijer / Queue
Last active December 28, 2015 06:39
// HOMEWORK WEEK 3 - Day 2
var LinkedList = function() {
this.head = null;
this.tail = null;
this.numItems = 0;
}
var newNode = function( data ) {
this.data = data;
this.next = null;
}
/*
ASSIGNMENT
Implement a stack data structure as a JavaScript object that contains the following methods:
push(data) - Adds a data element to the stack
The parameter is the data element to add to the stack.
pop(callback) - Removes a data element from the stack
The parameter to pop is a callback function that should expect two parameters - err and value. The callback's first param, err, is set to null if the pop operation was successful or "Underflow" if the stack was empty when called. The callback's second parameter, value, is the value removed from the stack.
@marijer
marijer / Linked List - Stack
Last active December 27, 2015 23:39
Linked List
// HOMEWORK WEEK 3, day 1 - Linked list
/*
prepend(data) - insert a new node with the value data at the beginning of the list
append(data) - insert a new node with the value data at the end of the list
pop_front(callback) - removes the first element of the list and invokes callback with the data value passed as the parameter to callback
pop_back(callback) - removes the last element of the list and invokes callback with the data value passed as the parameter to callback
*/