-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamquestion21.js
More file actions
48 lines (45 loc) · 948 Bytes
/
Copy pathexamquestion21.js
File metadata and controls
48 lines (45 loc) · 948 Bytes
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
function Stack() {
this.arr = [];
this.pop = function() {
if (this.arr.length == 0) {
return "Underflow";
}
return this.arr.pop();
};
this.push = function(el) {
return this.arr.push(el);
};
this.peek = function() {
return this.arr[this.arr.length - 1];
};
this.isEmpty = function() {
return (this.arr.length === 0);
};
}
function arrayStack(array) {
var f = new Stack();
var n = array.length;
for (var i = 0; i < n; i++) {
f.push(array[i]);
}
return f;
}
function stackPalindrome(array)
{
var x = arrayStack(array);
var i = 0;
while( x.isEmpty() == false )
{
if(x.peek()== array[i])
{
i=i+1;
x.pop();
}
else
{
return false;
}
}
return true;
}
console.log(stackPalindrome([1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1]))