将堆栈作为参数传递给fuction [英] Pass stack as parameter to fuction

查看:106
本文介绍了将堆栈作为参数传递给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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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