What are the differences between vectors, sets, and tuples in programming?
编程中的向量,集合和元组之间有什么区别?
6 个解决方案
#1
- Vector: Ordered collection of objects of the same type.
- Set: Unordered collection of objects, possibly of the same type or possibly different depending on the collection type and language. Any given object can only appear once.
- Tuple: Ordered collection of objects of different types.
矢量:相同类型的对象的有序集合。
设置:无序的对象集合,可能具有相同类型或可能不同,具体取决于集合类型和语言。任何给定的对象只能出现一次。
元组:有序收集不同类型的对象。
#2
A vector
is an ordered sequence of items that does allow duplicates.
向量是一个有序的项目序列,它允许重复。
A set
is a collection of items that is unordered and does not allow duplicates.
集合是无序的项目集合,不允许重复。
A tuple
is an ordered sequence of items of a given length.
元组是给定长度的有序项目序列。
#3
A tuple is a heterogeneous collection of objects, which should be treated as a single unit: for example, ("John", "Smith", 30) is a (String, String, Integer) tuple.
元组是异构的对象集合,应将其视为单个单元:例如,(“John”,“Smith”,30)是(String,String,Integer)元组。
A list (in C++: and also vector) is a homogeneous collection of objects -- that is, each object can be treated uniformly. Whether they are actually the same type depends on the language, but the point is that they can be processed the same way.
列表(在C ++中:也是向量)是一个同类的对象集合 - 也就是说,每个对象都可以统一处理。它们实际上是否是同一类型取决于语言,但关键是它们可以以相同的方式处理。
A set is an unordered unique homogenous collection -- you know what objects it contains, and what type they are, but not in what order, and it only contains one of each object.
集合是一个无序的唯一同源集合 - 您知道它包含哪些对象,它们是什么类型,但不是以什么顺序,它只包含每个对象中的一个。
#4
Vectors have an ordering
向量有一个排序
Tuples are ordered and can have repeat elements.
元组是有序的,可以有重复元素。
Sets are unordered and repeat elements do not change the set.
集合是无序的,重复元素不会更改集合。
For example: {a,b}, {b,a}, and {b,b,a} are all the same set, while (a,b), (b,a) and (b,b,a) are all different tuples.
例如:{a,b},{b,a}和{b,b,a}都是相同的集合,而(a,b),(b,a)和(b,b,a)是所有不同的元组。
#5
Mathematically
A tuple has properties that distinguish it from a set.
元组具有将其与集合区分开的属性。
- A tuple may contain multiple instances of the same element, so tuple (1,2,2,3) != (1,2,3) but set {1,2,2,3} = {1,2,3}.
元组可能包含同一元素的多个实例,因此元组(1,2,2,3)!=(1,2,3)但设置{1,2,2,3} = {1,2,3} 。
- Tuple elements are ordered: tuple (1,2,3) != (3,2,1), but set {1,2,3} = {3,2,1}.
元组元素是有序的:元组(1,2,3)!=(3,2,1),但是设置{1,2,3} = {3,2,1}。
- A tuple has a finite number of elements, while a set or a multiset may have an infinite number of elements.
元组具有有限数量的元素,而集合或多集合可具有无限数量的元素。
Vector is a different type represented by multiple tuples.
Vector是由多个元组表示的不同类型。
Cheers :-)
#6
Vectors have an ordering, sets do not (and can't have duplicates), and tuples are close to vectors but are usually used more like structs in practice.
向量具有排序,集合不具有(并且不能具有重复),并且元组接近向量但通常在实践中更像结构。
#1
- Vector: Ordered collection of objects of the same type.
- Set: Unordered collection of objects, possibly of the same type or possibly different depending on the collection type and language. Any given object can only appear once.
- Tuple: Ordered collection of objects of different types.
矢量:相同类型的对象的有序集合。
设置:无序的对象集合,可能具有相同类型或可能不同,具体取决于集合类型和语言。任何给定的对象只能出现一次。
元组:有序收集不同类型的对象。
#2
A vector
is an ordered sequence of items that does allow duplicates.
向量是一个有序的项目序列,它允许重复。
A set
is a collection of items that is unordered and does not allow duplicates.
集合是无序的项目集合,不允许重复。
A tuple
is an ordered sequence of items of a given length.
元组是给定长度的有序项目序列。
#3
A tuple is a heterogeneous collection of objects, which should be treated as a single unit: for example, ("John", "Smith", 30) is a (String, String, Integer) tuple.
元组是异构的对象集合,应将其视为单个单元:例如,(“John”,“Smith”,30)是(String,String,Integer)元组。
A list (in C++: and also vector) is a homogeneous collection of objects -- that is, each object can be treated uniformly. Whether they are actually the same type depends on the language, but the point is that they can be processed the same way.
列表(在C ++中:也是向量)是一个同类的对象集合 - 也就是说,每个对象都可以统一处理。它们实际上是否是同一类型取决于语言,但关键是它们可以以相同的方式处理。
A set is an unordered unique homogenous collection -- you know what objects it contains, and what type they are, but not in what order, and it only contains one of each object.
集合是一个无序的唯一同源集合 - 您知道它包含哪些对象,它们是什么类型,但不是以什么顺序,它只包含每个对象中的一个。
#4
Vectors have an ordering
向量有一个排序
Tuples are ordered and can have repeat elements.
元组是有序的,可以有重复元素。
Sets are unordered and repeat elements do not change the set.
集合是无序的,重复元素不会更改集合。
For example: {a,b}, {b,a}, and {b,b,a} are all the same set, while (a,b), (b,a) and (b,b,a) are all different tuples.
例如:{a,b},{b,a}和{b,b,a}都是相同的集合,而(a,b),(b,a)和(b,b,a)是所有不同的元组。
#5
Mathematically
A tuple has properties that distinguish it from a set.
元组具有将其与集合区分开的属性。
- A tuple may contain multiple instances of the same element, so tuple (1,2,2,3) != (1,2,3) but set {1,2,2,3} = {1,2,3}.
元组可能包含同一元素的多个实例,因此元组(1,2,2,3)!=(1,2,3)但设置{1,2,2,3} = {1,2,3} 。
- Tuple elements are ordered: tuple (1,2,3) != (3,2,1), but set {1,2,3} = {3,2,1}.
元组元素是有序的:元组(1,2,3)!=(3,2,1),但是设置{1,2,3} = {3,2,1}。
- A tuple has a finite number of elements, while a set or a multiset may have an infinite number of elements.
元组具有有限数量的元素,而集合或多集合可具有无限数量的元素。
Vector is a different type represented by multiple tuples.
Vector是由多个元组表示的不同类型。
Cheers :-)
#6
Vectors have an ordering, sets do not (and can't have duplicates), and tuples are close to vectors but are usually used more like structs in practice.
向量具有排序,集合不具有(并且不能具有重复),并且元组接近向量但通常在实践中更像结构。