如何以随机顺序混合堆栈值? [英] How to mix Stack values in random order?

查看:55
本文介绍了如何以随机顺序混合堆栈值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以发布代码吗?

谢谢

Can someone post a code?

Thanks

推荐答案

不能混合使用堆栈,除非您弹出所有项目,对它们重新排序,然后再次将它们推回. 根据定义,被压入堆栈的第一个项目是最后一个被压出的项目,被压入堆栈的最后一个是弹出的第一个项目.
想想一堆硬币:您只能取下最上面的硬币而不会塌陷.如果要重新排序硬币,则必须将它们全部删除,然后以不同的顺序重新堆叠它们.
Stacks cannot be mixed, unless you pop all the items off, reorder them, and then push them back on again.
By definition, the first item pushed onto a stack is the last item out, and the last item pushed on is the first popped off.
Think of a pile of coins: you can only take the top coin off without the pile collapsing. If you want to re-order the coins, you must remove them all, and re-stack them in a different order.


为此使用List<T>.您将具有随机访问权限,并且可以通过在末尾添加和删除项来像堆栈一样使用它.
Uses a List<T> for that. You will have random access and it can be used like a stack by adding and removing items at the end.


这篇关于如何以随机顺序混合堆栈值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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