Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Stack Implementation in Javascript

array = []
top = -1

function push(data){
	array[++top] = data
}

function pop(){
	if (top == -1) return "Empty Stack"
	ans = array[top]
	top--
	return ans
}

function peek(){
	if (top == -1) return "Empty Stack"
	return array[top]
}
Source by course.masaischool.com #
 
PREVIOUS NEXT
Tagged: #Stack #Implementation #Javascript
ADD COMMENT
Topic
Name
7+5 =