<body>
<script>
const max = 5;
const max = 5;
const stack = [];
let SP = 0;
let count = 0;
const push = function(data)
{
if (count === max)
{
return false;
}
stack[SP] = data;
count++;
SP++;
return true;
}
const pop = function()
{
if (count === 0)
{
return null;
}
SP--;
count--;
return stack[SP];
}
const printStack = function()
{
let a = [];
for (let i = 0; i < count; i++)
{
a.push(stack[i]);
}
console.log(a.join());
}
console.log(push({a:1}));
console.log(push(22));
console.log(push(33));
console.log(push(44));
console.log(push(55));
console.log(push(66));
console.log(pop());
console.log(pop());
console.log(pop());
console.log(pop());
console.log(pop());
console.log(pop());
</script>
</body>
'JavaScript' 카테고리의 다른 글
22.08.23 opacity,translate 강의 코드 (0) | 2022.08.23 |
---|---|
que 내용정리 (0) | 2022.08.21 |
dom 강의2 (0) | 2022.08.18 |
dom 강의 정리 (0) | 2022.08.17 |
bubblesort 강의 정리 (0) | 2022.08.16 |