《Accelerated C++》导读(Chapter 5)

Code:[ZachxPKU/AcceleratedCPlusPlus]

Chapter 5 Using Sequential containers and analyzing strings

5.1 Separating students into categories

5.1.1 Erasing elements in place

5.1.2 Sequential versus random access

5.2 Iterators

5.3 Using iterators instead of indices

5.4 Rethinking our data structure for better performance

5.5 The list type

Just as vectors are optimized for fast random access, lists are optimized for fast insertion and deletion anywhere within the container.

向量(Vectors)是为快速随机访问而优化,列表(lists)是为在容器中快速插入和删除而优化。

5.5.1 Some important differnces

5.5.2 Why bother?

vector 和 list 的使用选择还是非常有技巧的,如何正确选用合适的容器,对于程序的效率和逻辑简洁性都有重要的影响。

5.6 Taking strings apart

  • <cctype> 第一个C C语言 第二个C char 定义了一些关于char的有用函数。

5.7 Testing our split function

5.8 Putting strings together

5.8.1 Framing a picture

5.8.2 Vertical concatenation

5.8.3 Horizontal concatenation

5.9 Details

vector有两个需要注意的操作:

  • v.reserve(n)
    • Reserves space to hold n elements, but does not initialize them. This operation does not change the size of the container. It affects only the frequency with which vector may have to allocate memory in response to repeated calls to insert or push_back.
  • v.resize(n)
    • Gives v a new size equal to n. If n is smaller than the current size of v, elements beyond n are removed from the vector. If n is greater than the current size, then new elements are added to v and initialized as appropriate to the type in v.

还可以学习一下<cctype>头文件中的一些函数,混个脸熟,知道有这些函数就行,避免遇到相关需求时,还得自己造轮子:

  • isspace( c ) true if c is a whitespace character.
  • isalpha( c ) true if c is an alphabetic character.
  • isdigit( c ) true if c is a digit character.
  • isalnum( c ) true if c is a letter or a digit.
  • ispunct( c ) true if c is a punctuation character.
  • isupper( c ) true if c is an uppercase letter.
  • islower( c ) true if c is a lowercase letter.
  • toupper( c ) Yields the uppercase equivalent to c
  • tolower( c ) Yields the lowercase equivalent to c

最后,这一章最重要的就是对 vector 和 list 两种容器的不同特性有一个初步的印象。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值