观察到的堆栈和队列

编程入门 行业动态 更新时间:2024-10-22 23:12:48
本文介绍了观察到的堆栈和队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在寻找一个 INotifyCollectionChanged 实施堆栈和队列。我可以推出自己的,但我不希望推倒重来。

I'm looking for an INotifyCollectionChanged implementation of Stack and Queue. I could roll my own but I don't want to reinvent the wheel.

推荐答案

使用栈和队列(按照定义),你只能访问队列的堆栈或头顶。这就是从列表区分它们。 (因此,这就是为什么你还没有找到一个)

With Stacks and Queues (almost by definition) you only have access to the top of the stack or head of the queue. It's what differentiates them from a List. (and so, that's why you haven't found one)

要回答虽然你可以写你自己的,我会做从的ObservableCollection 导出,然后在实施推栈的情况下, 为插入偏移0(和流行为返回指数0,那么 RemoveAt移除指数0 );或用队列你可以只 到列表的末尾添加到排队,以及抢并删除第项目,与堆栈,用于出列。在插入,添加和 RemoveAt移除的操作将被称为上底层的ObservableCollection 等导致 Col​​lectionChanged 事件被解雇。

To answer though you could write your own, I would do it by deriving from ObservableCollection, then in the case of a stack implementing the Push as an Insert at offset 0 (and pop as returning index 0 then RemoveAt index 0); or with a queue you could just Add to the end of the list to Enqueue, and the grab and remove the first item, as with the stack, for Dequeue. The Insert, Add and RemoveAt operations would be called on the underlying ObservableCollection and so cause the CollectionChanged event to be fired.

您也可能会说,你只是想绑定或当一个项目,你都应该有机会获得变化的通知。你会再次创建自己的类,从堆栈或队列导出,手动触发CollectionChanged事件时:

You might also be saying that you simply want to bind or be notified when the one item you are supposed to have access to changes. You would create your own class again, derived from Stack or Queue, and fire the CollectionChanged event manually when:

  • 的东西被压入或弹出从堆栈中
  • 东西是从队列中离开
  • 东西被排队队列,当队列为previously空

更多推荐

观察到的堆栈和队列

本文发布于:2023-10-27 18:46:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534224.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:堆栈   队列   观察到

发布评论

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

>www.elefans.com

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