“容器”和“数据结构”的区别是什么?

时间:2022-07-15 16:37:44

What is a container? As I understand it:

一个容器是什么?我的理解:

  • An abstract data type is merely a logical description of the way the data will be stored and the operations that will be permitted on that data. For example, a stack is defined as a data type with the operations push, pop, etc. and LIFO access.

    抽象数据类型只是数据存储方式和数据上允许的操作的逻辑描述。例如,堆栈被定义为具有操作push、pop等和LIFO访问的数据类型。

  • A data structure is the actual implementation of this abstract definition, in some computer programming language, for example, a stack in C++ is implemented in the standard library, as std::stack.

    数据结构是这个抽象定义的实际实现,在某些计算机编程语言中,例如,在标准库中实现c++中的堆栈,称为std::stack。

Firstly, please correct/enhance my current understanding of the aforementioned distinction.

首先,请纠正/加强我对上述区别的理解。

Secondly, what exactly is a container? I hear this word thrown around quite often. Is it the same as my definition of a data structure?

第二,容器到底是什么?我经常听到这个词。它和我对数据结构的定义一样吗?

Also, wikipedia has three separate entries for these terms.

此外,*有三个独立的词条。

4 个解决方案

#1


1  

You're correct in your impressions of ADT vs data structure- although they're interchangeable to a fairly great extent. An ADT is explicitly abstract, a data structure is a more general term that can be totally abstract, or refer to implementation details as well.

你对ADT和数据结构的印象是正确的——尽管它们在很大程度上是可以互换的。ADT是显式抽象的,数据结构是一个更通用的术语,可以是完全抽象的,也可以是指实现细节。

A container is a very abstract idea, but generally it implies (to me anyway) some form of encapsulation- in the sense that it might mask complexities of an underlying object, or possibly present a uniform interface to a range of different possible underlying objects. It's a word so firmly rooted in the programmer vocabulary that people use it all the time, and as such its meaning is very blurry. ;)

容器是一个非常抽象的概念,但通常它暗示(对我来说)某种形式的封装——从某种意义上说,它可能掩盖底层对象的复杂性,或者可能为一系列不同可能的底层对象提供统一的接口。这个词深深植根于程序员的词汇表中,以至于人们一直在使用它,因此它的含义非常模糊。,)

#2


1  

Nothing, really. They're just two words for the same term, as we humans love to do. However, afaik, the official CS term is data structure, and the C++ Standard has specific C++ requirements for Container. However, in general, they are equivalent.

没什么,真的。它们只是同一个词的两个词,就像我们人类喜欢做的一样。但是,afaik,官方的CS术语是数据结构,c++标准对容器有明确的c++要求。然而,总的来说,它们是等价的。

#3


1  

A Container is a subset of data structures. C++ imposes special requirements on containers, which are implementations of different data structures.

容器是数据结构的子集。c++对容器施加了特殊的要求,容器是不同数据结构的实现。

A data structure is, per wikipedia: "a particular way of storing and organizing data". A container is a C++ construct that is a collection of records, which is itself a data structure.

根据*,数据结构是“存储和组织数据的一种特殊方式”。容器是一个c++构造,它是记录的集合,它本身就是一个数据结构。

#4


0  

As said by other, those terms are so widely used that they are used with various meanings, but here are the usages I have most often encountered.

正如其他人所说,这些术语被广泛使用,它们有不同的含义,但是下面是我经常遇到的用法。

Data structure is a term from computer science, it can be used in a theoratical discussion without reference to any specific language. There are many data structures discussed in books about algorithms, like queues, trees, hashtables... A data structure can be implemented in virtually any language.

数据结构是计算机科学中的一个术语,它可以用于理论讨论而不涉及任何特定的语言。书中讨论了很多关于算法的数据结构,比如队列、树、散列表……几乎任何语言都可以实现数据结构。

Container is a term rather used in the contect of a specific language, when there is an available library of already implemented containers that the programmer can use right away. Several disctinct libraries can implement the same (abstract) data structure (for instance, a simply linked list), but with distinct containers, i.e. distinct source code and distinct names (one could be called "queue", another one "fifo", and a third one "stack").

容器是一个术语,在特定语言的框架中使用,当有一个可用的已经实现的容器库时,程序员可以立即使用。几个disctinct库可以实现相同(抽象)的数据结构(例如,一个简单的链表),但是有不同的容器,例如不同的源代码和不同的名称(一个可以称为“queue”,另一个称为“fifo”,第三个称为“stack”)。

Furthermore, a container must be a way to store other types, e.g. vector stores ints. As an example, there are several ways to represent a graph in memory: adjacency matrix, adjacency lists, forward-star... All of these are data structures, but they are not containers, as they do not contain other types, they just represent the nodes and links of the graph. The data stored by these data structures are the nodes and links.

此外,容器必须是存储其他类型的方法,例如,向量存储int。例如,在内存中有几种表示图的方法:邻接矩阵、邻接表、forward-star…所有这些都是数据结构,但它们不是容器,因为它们不包含其他类型,它们只是表示图的节点和链接。这些数据结构存储的数据是节点和链接。

#1


1  

You're correct in your impressions of ADT vs data structure- although they're interchangeable to a fairly great extent. An ADT is explicitly abstract, a data structure is a more general term that can be totally abstract, or refer to implementation details as well.

你对ADT和数据结构的印象是正确的——尽管它们在很大程度上是可以互换的。ADT是显式抽象的,数据结构是一个更通用的术语,可以是完全抽象的,也可以是指实现细节。

A container is a very abstract idea, but generally it implies (to me anyway) some form of encapsulation- in the sense that it might mask complexities of an underlying object, or possibly present a uniform interface to a range of different possible underlying objects. It's a word so firmly rooted in the programmer vocabulary that people use it all the time, and as such its meaning is very blurry. ;)

容器是一个非常抽象的概念,但通常它暗示(对我来说)某种形式的封装——从某种意义上说,它可能掩盖底层对象的复杂性,或者可能为一系列不同可能的底层对象提供统一的接口。这个词深深植根于程序员的词汇表中,以至于人们一直在使用它,因此它的含义非常模糊。,)

#2


1  

Nothing, really. They're just two words for the same term, as we humans love to do. However, afaik, the official CS term is data structure, and the C++ Standard has specific C++ requirements for Container. However, in general, they are equivalent.

没什么,真的。它们只是同一个词的两个词,就像我们人类喜欢做的一样。但是,afaik,官方的CS术语是数据结构,c++标准对容器有明确的c++要求。然而,总的来说,它们是等价的。

#3


1  

A Container is a subset of data structures. C++ imposes special requirements on containers, which are implementations of different data structures.

容器是数据结构的子集。c++对容器施加了特殊的要求,容器是不同数据结构的实现。

A data structure is, per wikipedia: "a particular way of storing and organizing data". A container is a C++ construct that is a collection of records, which is itself a data structure.

根据*,数据结构是“存储和组织数据的一种特殊方式”。容器是一个c++构造,它是记录的集合,它本身就是一个数据结构。

#4


0  

As said by other, those terms are so widely used that they are used with various meanings, but here are the usages I have most often encountered.

正如其他人所说,这些术语被广泛使用,它们有不同的含义,但是下面是我经常遇到的用法。

Data structure is a term from computer science, it can be used in a theoratical discussion without reference to any specific language. There are many data structures discussed in books about algorithms, like queues, trees, hashtables... A data structure can be implemented in virtually any language.

数据结构是计算机科学中的一个术语,它可以用于理论讨论而不涉及任何特定的语言。书中讨论了很多关于算法的数据结构,比如队列、树、散列表……几乎任何语言都可以实现数据结构。

Container is a term rather used in the contect of a specific language, when there is an available library of already implemented containers that the programmer can use right away. Several disctinct libraries can implement the same (abstract) data structure (for instance, a simply linked list), but with distinct containers, i.e. distinct source code and distinct names (one could be called "queue", another one "fifo", and a third one "stack").

容器是一个术语,在特定语言的框架中使用,当有一个可用的已经实现的容器库时,程序员可以立即使用。几个disctinct库可以实现相同(抽象)的数据结构(例如,一个简单的链表),但是有不同的容器,例如不同的源代码和不同的名称(一个可以称为“queue”,另一个称为“fifo”,第三个称为“stack”)。

Furthermore, a container must be a way to store other types, e.g. vector stores ints. As an example, there are several ways to represent a graph in memory: adjacency matrix, adjacency lists, forward-star... All of these are data structures, but they are not containers, as they do not contain other types, they just represent the nodes and links of the graph. The data stored by these data structures are the nodes and links.

此外,容器必须是存储其他类型的方法,例如,向量存储int。例如,在内存中有几种表示图的方法:邻接矩阵、邻接表、forward-star…所有这些都是数据结构,但它们不是容器,因为它们不包含其他类型,它们只是表示图的节点和链接。这些数据结构存储的数据是节点和链接。