Skip to content

Commit 356a449

Browse files
fix: issue 116 with std::sort (#118)
1 parent a149562 commit 356a449

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

documents/en/vol1-fundamentals/ch11/03-algorithms-intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ auto baz = [a, &b]() {
7979
8080
## Sorting—`std::sort` and `std::stable_sort`
8181

82-
Sorting is likely the most frequently used operation in the algorithms library. `std::sort` accepts two iterators (starting with C++20, you can pass the container directly) and sorts in ascending order by default. Under the hood, it uses Introsort—combining the advantages of quicksort, heapsort, and insertion sort, with an average and worst-case time complexity of O(n log n):
82+
Sorting is likely the most frequently used operation in the algorithms library. `std::sort` accepts two iterators and sorts in ascending order by default. To pass the whole container directly, use `std::ranges::sort` (C++20): `std::ranges::sort(v)`. Under the hood, it uses Introsort—combining the advantages of quicksort, heapsort, and insertion sort, with an average and worst-case time complexity of O(n log n):
8383

8484
```cpp
8585
std::vector<int> v = {5, 2, 9, 1, 5, 6};

documents/vol1-fundamentals/ch11/03-algorithms-intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ std::for_each(data.begin(), data.end(), [&sum](int x) { sum += x; });
6565
6666
## 排个序——std::sort 与 std::stable_sort
6767
68-
排序大概是算法库里出场率最高的操作了。`std::sort` 接受两个迭代器(从 C++20 开始可以直接传容器),默认按升序排列。底层是 Introsort——结合了快排、堆排和插入排序的优点,平均和最坏时间复杂度都是 O(n log n):
68+
排序大概是算法库里出场率最高的操作了。`std::sort` 接受两个迭代器,默认按升序排列。想直接传整个容器?那是 `std::ranges::sort`,C++20 起才有(`std::ranges::sort(v)`)。底层是 Introsort——结合了快排、堆排和插入排序的优点,平均和最坏时间复杂度都是 O(n log n):
6969
7070
```cpp
7171
std::vector<int> v = {5, 2, 8, 1, 9, 3};

0 commit comments

Comments
 (0)