Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="box">
  <div id="stackview"></div>
  <div class="stackcontrol">
    <select id="option"><option value="Stack">Stack</option><option value="Queue">Queue</option></select>
    <input type="button" id="push" value="push" />
    <input placeholder="Enter number here" type="text" id="input" />
    <input type="button" id="pop" value="pop" /></div>
  <div id="stackmsg"></div>
  <a href="http://rohansakahle.com" title="Web Application Developer">www.rohansakhale.com</a>
</div>
              
            
!

CSS

              
                .stackcontrol {
  margin-top: 20px;
}

.box {
  margin: 20px auto;
  text-align: center;
  width: 500px;
  height: 450px;
  border-radius: 20px;
  box-shadow: 0 0 10px #000;
  padding: 20px;
}

input[type=text] {
  padding: 10px;
  border-radius: 10px;
  border: 0;
  box-shadow: 0 0 5px #000;
}

input[type=button] {
  margin: 0 10px 0 10px;
  width: 75px;
  padding: 10px;
  border-radius: 20px;
  box-shadow: 0 0 10px #000;
  border: 0;
  cursor: pointer;
}

input:hover {
  box-shadow: 0 0 5px #b1b1b1;
}

p {
  background: darkseagreen;
  width: 98%;
  margin: 0;
  border: 2px dotted #000;
}

#stackview {
  width: 80%;
  height: 55%;
  margin: 5%;
  padding: 5%;
  background: #eaeaea;
  border-radius: 10px;
  -webkit-transition: all 3s ease-out;
  -moz-transition: all 3s ease-out;
  -o-transition: all 3s ease-out;
  transition: all 3s ease-out;
}

#stackmsg {
  margin: 10px;
}

.error {
  color: #ff0000;
}

.success {
  color: #00ff00;
}
              
            
!

JS

              
                try {
  // Variables
  var m = document.getElementById("stackmsg");
  var stackview = document.getElementById("stackview");
  var options = document.getElementById("option");
  var valueHandle = document.getElementById("input");

  function Stack() {
    var sp = 10;
    var stk = new Array(10);
    this.push = function(v) {
      if (sp == 0) {
        this.print("error", "Stack is Full");
      } else {
        stk[--sp] = v;
        this.print("push", "Success", v);
      }
    };
    this.pop = function() {
      if (sp == 10) {
        this.print("error", "Stack is Empty");
      } else {
        var v = stk[sp++];
        this.print("pop", "Success", v);
      }
    };
    this.print = function(type, msg, value) {
      if (type == "error") {
        m.className = "error";
      } else if (type == "push") {
        var sp = document.createElement("p");
        var txtNode = document.createTextNode(value);
        sp.appendChild(txtNode);
        stackview.insertBefore(sp, stackview.childNodes[0]);
        m.className = "success";
      } else if (type == "pop") {
        stackview.removeChild(stackview.childNodes[0]);
        m.className = "success";
      }
      m.innerHTML = msg;
    };
  };

  function Queue() {
    var queArray = new Array();
    this.enqueue = function(v) {
      if (queArray.length == 10) {
        this.print("error", "Queue is Full");
      } else {
        queArray.push(v);
        this.print("enqueue", "Successfully Added", v);
      }
    };
    this.dequeue = function() {
      if (queArray.length == 0) {
        this.print("error", "Queue is Empty");
      } else {
        queArray.shift();
        this.print("dequeue", "Successfully Added");
      }
    };
    this.print = function(type, msg, value) {
      if (type == "error") {
        m.className = "error";
      } else if (type == "enqueue") {
        var sp = document.createElement("p");
        var txtNode = document.createTextNode(value);
        sp.appendChild(txtNode);
        stackview.appendChild(sp);
        m.className = "success";
      } else if (type == "dequeue") {
        stackview.removeChild(stackview.firstChild);
        m.className = "success";
      }
      m.innerHTML = msg;
    };
  };

  // Stack Object
  var s = new Stack();
  // Queue Object
  var e = new Queue();

  // Stack Execute
  function sExecute() {
    var pushHandle = document.getElementById("push");
    var popHandle = document.getElementById("pop");
    pushHandle.value = "Push";
    popHandle.value = "Pop";

    pushHandle.onclick = function() {
      var val = valueHandle.value;
      if (val != "") {
        s.push(val);
      } else {

        m.innerHTML = "Enter valid value to push";
        m.className = "error";
      }
      valueHandle.value = "";
    };
    popHandle.onclick = function() {
      s.pop();
    };
  };

  // Queue Execute
  function qExecute() {
    var pushHandle = document.getElementById("push");
    var popHandle = document.getElementById("pop");
    pushHandle.value = "Enqueue";
    popHandle.value = "Dequeue";

    pushHandle.onclick = function() {
      var val = valueHandle.value;
      if (val != "") {
        e.enqueue(val);
      } else {
        var m = document.getElementById("stackmsg");
        m.innerHTML = "Enter valid value to enqueue";
        m.className = "error";
      }
      valueHandle.value = "";
    };
    popHandle.onclick = function() {
      e.dequeue();
    };

  };

  // On change Function for Select Option
  function changeModel() {
    var stackview = document.getElementById("stackview");
    while (stackview.lastChild != null)
      stackview.removeChild(stackview.lastChild);
    if (options.value == "Stack") {
      sExecute();
    } else {
      qExecute();
    }

  }
  options.onchange = changeModel;
  window.onload = sExecute;
} catch (e) {
  alert(e);
}
              
            
!
999px

Console