-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.html
57 lines (52 loc) · 1.25 KB
/
stack.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stack</title>
</head>
<body>
<script>
let data= [];
let currentSize =data.length;
let max=5
// Though we can add element using push method but it will not remain data stucture so we make a function
function push(val) {
if (currentSize>=max) {
alert('stack value is full you cannot add'+ + val )
}
else{
data[currentSize]=val;
console.log(data[currentSize]=val);
currentSize+=1
}
}
function pop() {
if (currentSize>0) {
currentSize-=1;
data.length = currentSize
}else{
alert('stack is already empty')
}
}
push(10)
push(20)
push(30)
push(40)
push(50)
// push(60)
// push(70)
// push(80)
// push(90)
// pop
push(70)
push(80)
push(90)
// pop()
// pop()
console.log(data);
nums = []
nums.length
</script>
</body>
</html>