Created
December 3, 2015 06:01
-
-
Save urstory/ff7ed003710f66576c89 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script> | |
// https://gist.github.com/urstory | |
// Stack : FILO | |
function Stack(){ | |
this.data = []; | |
this.push = function(d){ | |
this.data.push(d); | |
}; | |
this.pop = function(){ | |
var length = this.data.length; | |
var d = this.data[length-1]; | |
// 0번째 위치한 1건 삭제. | |
this.data.splice(length-1,1); | |
return d; | |
}; | |
this.isEmpty = function(){ | |
if(this.data.length > 0) | |
return false; | |
else | |
return true; | |
}; | |
} | |
var stack = new Stack(); | |
stack.push('hello'); | |
stack.push('hi'); | |
stack.push('javascript'); | |
var v1 = stack.pop(); // javascript | |
var v2 = stack.pop(); // hi | |
var v3 = stack.pop(); // hello | |
var v4 = stack.isEmpty(); // 비어있으면 true | |
alert(v1); | |
alert(v2); | |
alert(v3); | |
alert(v4); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment