This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var LinkedList = function() { | |
this.head = null; | |
this.tail = null; | |
this.numItems = 0; | |
} | |
var newNode = function( data ) { | |
this.data = data; | |
this.next = null; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
*/ |
NewerOlder