在面向对象的程序设计里,一般都提供了实现队列(queue)和堆栈(stack)的方法,而对于JS来说,我们可以实现数组的相关操作,来实现队列和堆栈的功能,看下面的相关介绍.
一 看一下它们的性质,这种性质决定了它们的使用场合
队列:是一种支持先进先出(FIFO)的集合,即先被插入的数据,先被取出!
QQEhgorMiDHEJmp1JRqVmqbGVJdCTAUVHHHo0kZNIkZrFYIyCoTxTffd/ftj957f4b7Bx7sIwtvf+hbrcodzz7DPd/aZ7hPqauuIRCLRbgptHgMikdiuSSJCJBJVkUSESCSqIokIkUhURRIRipGoiiQiRCJRFUlEiESiKpKIEIlEVSQRIRKJqkgiQiQSVZFEhEgkqiKJCJFIVEUSESKRqIokIkQiURVJRIhEoiqSiBCJRFUkESESiapIIkIkElWRRIRIJKoiiQiRSFRFEhEikaiKJCJEIlEVSUSIRKIqkogQiURVJBEhEomqSCJCJBJVkUSESCSqIokIkUhURRIRIpGoiiQiRCJRFUlEiESiKpKIEIlEVSQRIRKJqthERIBAIBCaCRIRAoGgCiQiBAJBFZqIiNQURqNRFEXpaTAajQBg5Sr+xQMezzRhGP5TI08gtCzssDpmrioN3ixM651997DbTGNrjydiMBj0er1Op0OJMa23er0eb+DPKxJsd2Y1C4oXSaQscoZIXFaYZpdkkm+SzVmneNzSVdsDtOV1lmJu6aPPTMxajvWkWTE5S1G1lKvWw7QRkrmiNBu+0WjU6XQ6nc5gMIiiaBqUnoNOp2PyYRbmPRGDwSBJUnFx8Z07dyRJEkWRdygUQZSUlOBbTa8aDIbGxkZRFB88ePDgwQMMylKetizYW0RRRL1jmWJwePCZoNPp2L+KzNFqtVqtFk/yf20JnNkfy3M0Wf5MSyWEf4VGo8FLGo2Grwl4m1arxWgoQsBnWdxsT6xpetHSnvoUM07myLeUwTOv32g01tTU1NbWAoBer5e4boHi2dLSUq1Wy/wRg8FgGr7RaCwqKtLr9aaxtdidAYDw8PBf/vKXLLWYTUaj8fPPP1+7dm1sbOzXX3+9adOmt956y2g0olgYjcbCwsKIiIj169dHR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