Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

stack function

function Stack() {
  let items = [];

  function push(element) {
    items.push(element);
  }

  function pop() {
    return items.pop();
  }

  function peek() {
    return items[items.length - 1];
  }

  function isEmpty() {
    return items.length === 0;
  }

  function size() {
    return items.length;
  }

  function clear() {
    items = [];
  }

  return {
    clear,
    push,
    pop,
    peek,
    isEmpty,
    size,
  };
}
Source by www.raulmelo.dev #
 
PREVIOUS NEXT
Tagged: #stack #function
ADD COMMENT
Topic
Name
9+3 =