将堆栈作为参数传递给fuction

编程入门 行业动态 更新时间:2024-10-05 13:31:18
本文介绍了将堆栈作为参数传递给fuction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好 如何将堆栈作为参数传递给函数 void sor(stack< int> s) { //////// } 首先感谢

推荐答案

这取决于你所谓的堆栈。如果这是一个数据结构( Stack(抽象数据类型) - 维基百科,免费的百科全书 [ ^ ], Stack(C ++) - 维基百科,免费的百科全书 [ ^ ], stack - C ++参考 [ ^ ]) ,你最好通过指针或引用传递它: It depends on what you call "stack". If this is a data structure (Stack (abstract data type) - Wikipedia, the free encyclopedia[^], Stack (C++) - Wikipedia, the free encyclopedia[^], stack - C++ Reference[^]), you should better pass it by pointer or by reference: void someFunction(stack * s) { /* ... */ } void someOtherFunction(stack & s) { /* ... */ } // and the like...

我应该解释原因吗?如果你真的需要解释,我担心它应该解释编程的基础知识,这很难适合这个论坛的格式。 无论如何,这个阅读可能是有用的: 7.2。按值传递参数;学习C ++ [ ^ ], 7.3。通过引用传递参数;学习C ++ [ ^ ], 7.4。按地址传递参数;学习C ++ [ ^ ], 6.7。指针简介;学习C ++ [ ^ ]。

-SA

Should I even explain why? If you really need the explanation, I'm afraid it should go as far as explaining the very basics of programming, which can hardly fit the format of this forum. Anyway, this reading could be useful: 7.2. Passing arguments by value; Learn C++[^], 7.3. Passing arguments by reference; Learn C++[^], 7.4. Passing arguments by address; Learn C++[^], 6.7. Introduction to pointers; Learn C++[^].

—SA

更多推荐

将堆栈作为参数传递给fuction

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

发布评论

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

>www.elefans.com

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