堆栈函数的实现在哪里?
我正在学习数据结构和算法
。我的老师告诉我以下内容:
push():push向栈中插入一个元素
pop():pop从栈中删除最后插入的元素
size():返回栈中元素的数量
isempty():返回一个布尔值,指示堆栈是否为空
top():返回栈顶元素,但不移除;如果堆栈为空,则返回错误。
这些功能的实现在哪里?这些是 C++ 的内置函数
吗?
I am learning data structures and algorithms
. My teacher told me the following:
push(): push inserts an element in the stack
pop(): pop deletes the last inserted element from the stack
size(): Returns the number of elements in the stack
isempty(): Returns a boolean indicating if the stack is empty
top(): returns the top element of the stack, without removing it; If stack is empty an error is returned.
Where are the implementations of these functions? Are these built-in functions
of C++?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您的老师正在解释可用于通用堆栈数据结构的函数。这些函数没有在任何地方特别实现,因为您的老师没有谈论任何特定的堆栈。你的老师甚至没有谈论 C++。现在您刚刚了解什么是堆栈:它们是可以用任何语言实现的抽象数据结构。它们是后进先出的容器。在课程的后面部分,您将了解树、队列、堆、列表以及各种其他抽象数据结构。在后面的课程中,您的老师可能会演示如何实现上面列出的功能。演示甚至可能是用 C++ 进行的。
Your teacher was explaining the functions available for the generic stack data structure. Those functions aren't implemented anywhere in particular because your teacher was not talking about any specific stack. Your teacher wasn't even talking about C++. Right now you're just learning about what a stack is: they're abstract data structures implementable in any language. They're last-in-first-out containers. Later in your course, you'll learn about trees, queues, heaps, lists, and all sorts of other abstract data structures. In a later lesson, your teacher will probably demonstrate how to implement the functions listed above. The demonstration might even be in C++.
这些是
std::stack
的成员函数,其中是C++标准库中的容器类(模板)。您可以在
头文件中找到实现。[但请注意,它是
empty()
,而不是isempty()
。]These are member functions for
std::stack
, which is a container class (template) in the C++ standard library.You can find the implementation in the
<stack>
header file.[Note that it's
empty()
, notisempty()
, though.]std::stack - 它位于标准库中,它是 c++ 的“一部分”,尽管它不是“内置函数”
std::stack - it's in the standard library, which is "part" of c++, although it's not a "built-in function"
如果您想了解如何创建自己的模板类和函数,请参阅
如果您想了解如何实现堆栈以及堆栈是什么,请阅读
如果您想要了解有关 C++ STL 中容器的更多信息,请阅读以下内容:
希望这些参考文献能够帮助您提出更具体的问题或要求对您尚不理解的内容进行澄清...
If you are trying to figure out how to create your own template classes and functions, see
If you want to understand how a stack could be implemented, and what a stack is, read
If you want to understand more about containers in C++ STL, read these:
Hopefully, these references will help you with asking a more specific question or to request clarification on something you don't yet understand...
要使用 stl,您必须将其全部或部分包含在您的文件中,或者在每次使用时引用 stl。
以下是 STL 实现的链接:
http://www.sgi.com/tech/stl/download.html
To use the stl you would have to include all or part of it in your files, or reference the stl each time you use it.
Here is a link to an implementation of the STL:
http://www.sgi.com/tech/stl/download.html