什么时候使用堆栈? [英] When to use a stack?

查看:361
本文介绍了什么时候使用堆栈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨晚我正在阅读有关实现自己的堆栈的信息。给出的示例

在每个

过程的开始和结束时将项目推入和离开堆栈(即在std模块中)。什么不太清楚这个

如何与类对象一起使用。在这种情况下,您是否必须在

类的每个公共程序等的开头按下堆栈上的

对象并在结束时将其弹出?我不知道你怎么知道

哪个对象是活跃的 - 或者这通常不是采用

堆栈的情况?


在此先感谢,

Andrew

Last night I was reading about implementing my own stack. The example
given pushes items on and off the stack at the start and end of each
procedure (ie. in a std module). What''s not so clear is how this
would work with class objects. In this case do you have to push the
object on the stack at the start of every public procedure etc. in the
class and pop it off at the end? I can''t see how else you can know
which object is active - or is this not normally a situation where a
stack is employed?

Thanks in advance,
Andrew

推荐答案

Andrew,

我没有完成很多堆栈实现,但是我的一般理解

是堆栈的一个用途是用于存储过程变量和内存

位置处理器打电话给其他程序所有当前的

过程变量都被填充到堆栈中以保留它们的值,并且

以及要从中恢复的内存位置,并且该过程继续执行
呼叫隐含的新内存位置
。新程序本身可以是
调用另一个程序并将其信息存储在同一个堆栈上,依此类推。

最后一个程序完成,将控制权返回给调用

程序从堆栈中弹出变量,最终完成,

返回控件,弹出变量等等。至少那是我带的神话

在我脑海里。堆栈还有其他用途,如解析

输入流。我相信你可以找到更多的学术解释。


我可以设想使用VB Collection作为一个堆栈,作为一个实际的

问题,它会存储VB对象的顺序可以用

索引控制。我写了很多商业和工程软件,而且我没有记住实现我真正称之为堆栈的东西。链接列表,

b-trees,数组,其他数据结构,其中一些可能像小堆栈一样被用作堆栈

。堆栈是一种非常低级别的数据类型,在现代业务编程中经常遇到这样的问题,其中目标通常是将封装的数据类型(对象),数据流拼凑在一起整个

使用更高级语言的应用程序。


我的
Andrew,
I haven''t done a lot of stack implementation, but my general understanding
is that one use of a stack is for storing procedure variables and memory
locations while processors call other procedures. All of the current
procedure variables get stuffed onto the stack to reserve their value, along
with the memory location to resume from, and the process continues execution
at the new memory location implied by the call. The new procedure may itself
call another procedure and store its info on the same stack, and so on.
Eventually the last procedure completes, returns control to the calling
procedure which pops its variables from the stack, eventually completes,
returns control, pops variables, etc. At least that is the myth I carry
around in my head. There are other uses for stacks, as in parsing streams of
input. I am sure you can find more academic explanations.

I can envision using a VB Collection for a stack, which, as a practical
matter, would store VB objects in an order that could be controlled with
indexes. I write a lot of business and engineering software and I do not
remember implementing something I would really call a stack. Linked lists,
b-trees, arrays, other data structures, some may have been used like a stack
on a small scale. A stack is a pretty low level data type not often
encountered as such in modern business programming where the goal often is
patching together encapsulated data types (objects), data streams and whole
applications using higher level languages.

My


0.02,

Bob


" Andrew" <豪****** @ hotmail.com>在消息中写道

新闻:9d ************************** @ posting.google.c om ...
0.02,
Bob

"Andrew" <ho******@hotmail.com> wrote in message
news:9d**************************@posting.google.c om...
昨晚我正在阅读有关实现自己的堆栈的信息。给出的示例在每个
过程的开始和结束时(即在std模块中)将项目推入和离开堆栈。什么不是很清楚这是如何使用类对象。在这种情况下,您是否必须在
类中的每个公共过程等的开始处将
对象推到堆栈上并在结束时将其弹出?我不知道你怎么知道
哪个对象是活跃的 - 或者这通常不是采用
堆栈的情况吗?

提前致谢,
Andrew
Last night I was reading about implementing my own stack. The example
given pushes items on and off the stack at the start and end of each
procedure (ie. in a std module). What''s not so clear is how this
would work with class objects. In this case do you have to push the
object on the stack at the start of every public procedure etc. in the
class and pop it off at the end? I can''t see how else you can know
which object is active - or is this not normally a situation where a
stack is employed?

Thanks in advance,
Andrew



嗨鲍勃,

非常感谢您的解释。


我原以为也许我可以实现一个堆栈来跟踪

对象当前有效但是从你用堆栈描述的内容

更适合程序甚至那时限制使用,因为vba

一旦完成就会自动返回上一个程序。


有没有其他方法来识别活动对象?事实上,我真正想要的是对象之前的对象。有点像

Application.Caller但适用于对象。


无论如何,感谢您对堆栈的想法 - 它有所启发

关于编程语言如何在表面下工作 -

有趣。


Rgds,

Andrew

" Bob Kilmer" < RP ***** @ yahoo.com>在消息新闻中写道:< ep ************** @ TK2MSFTNGP09.phx.gbl> ...
Hi Bob,
Thanks a lot for your explaination.

I had thought maybe I could implement a stack to keep track of what
object was currently active but from what you describe using a stack
is more suited to procedures and even then of limited use since vba
will return automatically to the previous procedure once finished.

Is there any other way to identify the active object? In fact what I
really want is the object prior to the active one. Kind of like
Application.Caller but applicable to objects.

In any case, thanks for your thoughts on stacks - it sheds some light
on how a programming language may be working beneath the surface -
interesting.

Rgds,
Andrew
"Bob Kilmer" <rp*****@yahoo.com> wrote in message news:<ep**************@TK2MSFTNGP09.phx.gbl>...
安德鲁,
我没有''我做了很多堆栈实现,但我的一般理解是,堆栈的一个用途是用于存储过程变量和内存位置,而处理器调用其他过程。所有当前的过程变量都被填充到堆栈中以保留它们的值,并继续从内存位置恢复,并且该过程继续执行
在新的内存位置隐含呼叫。新程序本身可以调用另一个程序并将其信息存储在同一个堆栈上,依此类推。
最后一个程序完成,将控制权返回给调用的
程序,该程序从中弹出变量堆栈,最终完成,
返回控制,弹出变量等。至少这是我头脑中携带的神话。堆栈还有其他用途,如解析输入流。我相信你可以找到更多的学术解释。

我可以设想使用一个VB集合作为一个堆栈,作为一个实际的事情,它将按顺序存储VB对象用
索引控制。我写了很多商业和工程软件,我不记得实现我真正称之为堆栈的东西。链接列表,b-trees,数组,其他数据结构,有些可能像小堆栈一样被小型使用。堆栈是一种非常低级别的数据类型,在现代业务编程中经常遇到这种类型,其目标通常是使用封装的数据类型(对象),数据流和整个应用程序来修补更高级别的语言。

我的
Andrew,
I haven''t done a lot of stack implementation, but my general understanding
is that one use of a stack is for storing procedure variables and memory
locations while processors call other procedures. All of the current
procedure variables get stuffed onto the stack to reserve their value, along
with the memory location to resume from, and the process continues execution
at the new memory location implied by the call. The new procedure may itself
call another procedure and store its info on the same stack, and so on.
Eventually the last procedure completes, returns control to the calling
procedure which pops its variables from the stack, eventually completes,
returns control, pops variables, etc. At least that is the myth I carry
around in my head. There are other uses for stacks, as in parsing streams of
input. I am sure you can find more academic explanations.

I can envision using a VB Collection for a stack, which, as a practical
matter, would store VB objects in an order that could be controlled with
indexes. I write a lot of business and engineering software and I do not
remember implementing something I would really call a stack. Linked lists,
b-trees, arrays, other data structures, some may have been used like a stack
on a small scale. A stack is a pretty low level data type not often
encountered as such in modern business programming where the goal often is
patching together encapsulated data types (objects), data streams and whole
applications using higher level languages.

My


这篇关于什么时候使用堆栈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆