用于Excel VBA的LIFO(Stack)算法/类

编程入门 行业动态 更新时间:2024-10-27 20:36:06
本文介绍了用于Excel VBA的LIFO(Stack)算法/类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在寻找在VBA for Excel中实现堆栈类。我想使用先进先出结构。有人以前遇到这个问题吗?你知道外部库处理结构,如Stack,Hastable,Vector ...(除了原来的Excel Collection等...)

I'm looking to implement a "Stack" Class in VBA for Excel. I want to use a Last In First Out structure. Does anyone came across this problem before ? Do you know external libraries handling structure such as Stack, Hastable, Vector... (apart the original Excel Collection etc...)

谢谢

推荐答案

这是一个非常简单的堆栈类。

Here is a very simple stack class.

Option Explicit Dim pStack As Collection Public Function Pop() As Variant With pStack If .Count > 0 Then Pop = .Item(.Count) .Remove .Count End If End With End Function Public Function Push(newItem As Variant) As Variant With pStack .Add newItem Push = .Item(.Count) End With End Function Public Sub init() Set pStack = New Collection End Sub

测试它

Option Explicit Sub test() Dim cs As New cStack Dim i As Long Set cs = New cStack With cs .init For i = 1 To 10 Debug.Print CStr(.Push(i)) Next i For i = 1 To 10 Debug.Print CStr(.Pop) Next i End With End Sub

Bruce

更多推荐

用于Excel VBA的LIFO(Stack)算法/类

本文发布于:2023-11-30 05:10:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648837.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:算法   VBA   Excel   Stack   LIFO

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!