Created
December 1, 2018 21:09
-
-
Save ceme/8a987956813bec21f741593f3963cba5 to your computer and use it in GitHub Desktop.
Stack and Queue Operations and Write to DOM in Vanilla JavaScript
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
https://codepen.io/anon/pen/dQaJBm?editors=1111 |
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
<div id="out"></div> |
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 out = document.querySelector('#out'); | |
var addBreak = function() { | |
var brDiv = document.createElement('br'); | |
out.appendChild(brDiv); | |
}; | |
var addText = function(text) { | |
var textNode = document.createTextNode(text.toString()); | |
out.appendChild(textNode); | |
}; | |
//Queue | |
var queue = []; | |
queue.unshift('boh'); | |
queue.unshift('bog'); | |
queue.unshift('bogo'); | |
queue.unshift('begone'); | |
var qres = queue.shift(); | |
addText(queue + ' : ' + qres); | |
//End Queue | |
addBreak(); | |
//Stack | |
var stack = []; | |
stack.push('one'); | |
stack.push('two'); | |
stack.push('three'); | |
stack.push('four'); | |
var sres = stack.pop(); | |
addText(stack + ' : ' + sres); | |
//End Stack |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment