什么是“集合”在C ++?什么时候有用? [英] What is a "set" in C++? When are they useful?

查看:193
本文介绍了什么是“集合”在C ++?什么时候有用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个困难的时间概念化c ++集,实际上一般设置。

I'm having a hard time conceptualizing c++ sets, actually sets in general.

他们是什么?它们如何有用?

What are they? How are they useful?

推荐答案

如果你对一般的理解有困难,不要感到不舒服。数学学士学位大多数花费在集合论的术语上:

Don't feel bad if you have trouble understanding sets in general. Most of a degree in mathematics is spent coming to terms with set theory:

http://en.wikipedia.org/wiki/Set%5Ftheory

将集合视为唯一无序对象的集合。在许多方面,它看起来像一个列表:

Think of a set as a collection of unique, unordered objects. In many ways it looks like a list:

{1,2,3,4}

{ 1, 2, 3, 4 }

是不重要的:

{4,3,2,1} = {1,2,3,4}

{ 4, 3, 2, 1} = { 1, 2, 3, 4}

和重复项将被忽略:

{1,1,2,3,4} = {1,2,3,4}

{ 1, 1, 2, 3, 4 } = { 1, 2, 3, 4}

C ++集是这个数学对象的实现,奇怪的特征是在内部排序。但这只是一个实现的细节,并且与理解数据结构无关。排序只是为了速度。

A C++ set is an implementation of this mathematical object, with the odd feature that is is sorted internally. But this is just a detail of implementation, and is not relevant to understanding the data structure. The sorting is just for speed.

这篇关于什么是“集合”在C ++?什么时候有用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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