Stack

Stack

후입선출(Last-In-First-Out)의 자료구조이다.

Constructor

new Stack()

Author:
  • yicho93@gmail.com
Example
var s = new Stack ();

Methods

(static) clear()

This method is used to nullify this stack and make all variables initial.
Example
var s = new Stack ();
s.push(1); 
s.push(2);
s.push(3);
s.clear();

(static) isEmpty()

This method is used to check if this stack is empty.
Example
var s = new Stack ();
var ret1 = s.isEmpty(); // ret1 = true
s.push(1);
var ret2 = s.isEmpty(); // ret2 = false
Returns:
This method returns ‘true’ if this stack is empty or ‘false’ if this stack is not empty.

(static) pop()

This method is used to remove value from this stack.
Example
var s = new Stack ();
s.push(1); 
s.push(2);
s.pop() // 2 will be removed.
Returns:
This method returns the vale which is poped.

(static) push(value)

This method is used to insert the specified value into this stack.
Example
var s = new Stack ();
s.push(1);
s.push(2);
Parameters:
Name Type Description
value undefined The value to be inserted to this stack.

(static) size()

This method is used to get the number of values in this stack.
Example
var s = new Stack ();
s.push(1); 
s.push(2);
s.push(3);
var size = s.size(); // size = 3
Returns:
This method returns the number of values in this stack.

(static) state()

This method shows state of this stack.
Example
var s = new Stack ();
s.push(1); 
s.push(2);
s.push(3);
s.state(); // 1, 2, 3

(static) top()

This method is used to get the last value in this stack, but does not remove.
Example
var s = new Stack ();
s.push(1); 
s.push(2);
s.push(3);
var ret = s.top() // ret1 = 3
Returns:
This method returns the last value of this stack.