stl set的使用

1.       set之间的比较

Standard C++ Library Reference

 

<set> Members

Operators

operator!=

Tests if the set or multiset object on the left side of the operator is not equal to the set or multiset object on the right side.

operator<

Tests if the set or multiset object on the left side of the operator is less than the set or multiset object on the right side.

operator<=

Tests if the set or multiset object on the left side of the operator is less than or equal to the set or multiset object on the right side.

operator==

Tests if the set or multiset object on the left side of the operator is equal to the set or multiset object on the right side.

operator>

Tests if the set or multiset object on the left side of the operator is greater than the set or multiset object on the right side.

operator>=

Tests if the set or multiset object on the left side of the operator is greater than or equal to the set or multiset object on the right side.

Specialized Template Functions

swap

Exchanges the elements of two sets or multisets.

Classes

set Class

Used for the storage and retrieval of data from a collection in which the values of the elements contained are unique and serve as the key values according to which the data is automatically ordered.

multiset Class

Used for the storage and retrieval of data from a collection in which the values of the elements contained need not be unique and in which they serve as the key values according to which the data is automatically ordered.

2Set支持的一些操作

注意,set不支持像vector一样的下标[]操作,如果想遍历元素,只能使用iterator来实现。

 

Standard C++ Library Reference

 

set Members

Typedefs

allocator_type

A type that represents the allocator class for the set object.

const_iterator

A type that provides a bidirectional iterator that can read a const element in the set.

const_pointer

A type that provides a pointer to a const element in a set.

const_reference

A type that provides a reference to a const element stored in a set for reading and performing const operations.

const_reverse_iterator

A type that provides a bidirectional iterator that can read any const element in the set.

difference_type

A signed integer type that can be used to represent the number of elements of a set in a range between elements pointed to by iterators.

iterator

A type that provides a bidirectional iterator that can read or modify any element in a set.

key_compare

A type that provides a function object that can compare two sort keys to determine the relative order of two elements in the set.

key_type

The type describes an object stored as an element of a set in its capacity as sort key.

pointer

A type that provides a pointer to an element in a set.

reference

A type that provides a reference to an element stored in a set.

reverse_iterator

A type that provides a bidirectional iterator that can read or modify an element in a reversed set.

size_type

An unsigned integer type that can represent the number of elements in a set.

value_compare

The type that provides a function object that can compare two elements to determine their relative order in the set.

value_type

The type describes an object stored as an element of a set in its capacity as a value.

Member Functions

begin

Returns an iterator that addresses the first element in the set.

clear

Erases all the elements of a set.

count

Returns the number of elements in a set whose key matches a parameter-specified key.

empty

Tests if a set is empty.

end

Returns an iterator that addresses the location succeeding the last element in a set.

equal_range

Returns a pair of iterators respectively to the first element in a set with a key that is greater than a specified key and to the first element in the set with a key that is equal to or greater than the key.

erase

Removes an element or a range of elements in a set from specified positions or removes elements that match a specified key.

find

Returns an iterator addressing the location of an element in a set that has a key equivalent to a specified key.

get_allocator

Returns a copy of the allocator object used to construct the set.

insert

Inserts an element or a range of elements into a set.

key_comp

Retrieves a copy of the comparison object used to order keys in a set.

lower_bound

Returns an iterator to the first element in a set with a key that is equal to or greater than a specified key.

max_size

Returns the maximum length of the set.

rbegin

Returns an iterator addressing the first element in a reversed set.

rend

Returns an iterator that addresses the location succeeding the last element in a reversed set.

set

Constructs a set that is empty or that is a copy of all or part of some other set.

size

Returns the number of elements in the set.

swap

Exchanges the elements of two sets.

upper_bound

Returns an iterator to the first element in a set that with a key that is equal to or greater than a specified key.

value_comp

Retrieves a copy of the comparison object used to order element values in a set.

 

2.       set插入的数据,默认会自动按照升序排列

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值