简体   繁体   English

如何在Javascript中创建多维堆栈?

[英]How to create a multi-dimensional stack in Javascript?

In 1D stack, I can implement this code below 在1D堆栈中,我可以在下面实现此代码

// Create 1D stack
var stack = new Array(1000)
stack.push(23)
stack.pop()

But for the 2D stack and multi-dimensional stack, how to implement this stack which can do the push and pop function? 但是对于2D堆栈和多维堆栈,如何实现这个可以执行推送和弹出功能的堆栈?

Here is the example to create 2D stack, 这是创建2D堆栈的示例,

 var s = new Array(100); for( let i=0;i<100;i++) { s[i] = []; for( let j=0; j<100; j++) { s[i][j] = i*j; } } console.log(s); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM