堆栈函数的实现在哪里?

发布于 2024-12-02 13:51:06 字数 314 浏览 1 评论 0原文

我正在学习数据结构和算法。我的老师告诉我以下内容:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

小清晰的声音 2024-12-09 13:51:06

您的老师正在解释可用于通用堆栈数据结构的函数。这些函数没有在任何地方特别实现,因为您的老师没有谈论任何特定的堆栈。你的老师甚至没有谈论 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++.

↙厌世 2024-12-09 13:51:06

这些是 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(), not isempty(), though.]

半山落雨半山空 2024-12-09 13:51:06

std::stack - 它位于标准库中,它是 c++ 的“一部分”,尽管它不是“内置函数”

std::stack - it's in the standard library, which is "part" of c++, although it's not a "built-in function"

踏雪无痕 2024-12-09 13:51:06

如果您想了解如何创建自己的模板类和函数,请参阅

如果您想了解如何实现堆栈以及堆栈是什么,请阅读

如果您想要了解有关 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...

浅笑轻吟梦一曲 2024-12-09 13:51:06

要使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文