$.Data.Stack() - Class
Data Structures are often needed in any programming model. Nedil JS supports few data structures without any size restriction.
Stack follows first in last out methodology. Stack data structure can be created in NedilJS using $.Data.Stack() class
Property
Methods
Example 1
This example demonstrates Stack operations using $.Data.Stack class
JS
HTML
CSS
$.domLoaded(function() { // create $.Data.Stack Object var st = new $.Data.Stack(); // push few elements st.push(12); st.push(57); st.push(23); function showContent() { var cont = ""; // iterate over the stack elements st.iterate(function(el) { cont += el + ", "; }); // show stack $.get("#stack").text(cont); } showContent(); $.get("#btn1").on("click", function() { var va = $.get("#inp").element().value.trim(); // push new element st.push(va); showContent(); }); $.get("#btn2").on("click", function() { // pop the top element var top = st.pop(); $.get("#pop").html("Removed Element : " + top); showContent(); }); });
Result
| |||||||||||||||||||