From 968d4fda27db6b8a90af2536360971a9fbbc3fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BA=91=E6=B5=A9?= Date: Fri, 25 Dec 2020 15:26:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=A0=E6=AD=A3=E4=B8=80=E4=B8=AA=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E6=8F=8F=E8=BF=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit std::sort 确实不可以对 std::list 进行排序,但不代表 list 不可以排序,实际上 std::list 也提供了成员函数 sort(),可以对 list 进行排序。 --- content/chapter2/chapter2-4-chinese.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/chapter2/chapter2-4-chinese.md b/content/chapter2/chapter2-4-chinese.md index b6a24fb..fcbe16a 100644 --- a/content/chapter2/chapter2-4-chinese.md +++ b/content/chapter2/chapter2-4-chinese.md @@ -95,4 +95,5 @@ void insert_sorted(C &v, const T &item) } ``` -当我们要将`std::vector`类型转换为其他类型时,需要注意的是并不是所有容器都支持`std::sort`。该函数所对应的算法需要容器为可随机访问容器,例如`std::list`就无法进行排序。 \ No newline at end of file +当我们要将`std::vector`类型转换为其他类型时,需要注意的是并不是所有容器都支持`std::sort`。该函数所对应的算法需要容器为可随机访问容器,例如`std::list`就无法用`std::sort`进行排序。 +不过,`std::list`可以使用成员函数`sort`进行排序。