对algo.h作注释

main
Khara0 7 months ago
parent 10fae69251
commit feeb30d02e

@ -1,4 +1,8 @@
#ifndef MYTINYSTL_ALGO_H_ /*这个头文件 algo.h 是 mystl 命名空间中的算法库实现,包含了大量的常用算法,如查找、排序、合并、替换等。
*/

#ifndef MYTINYSTL_ALGO_H_
#define MYTINYSTL_ALGO_H_ #define MYTINYSTL_ALGO_H_
#ifdef _MSC_VER #ifdef _MSC_VER
@ -6,7 +10,9 @@
#pragma warning(disable : 4244) #pragma warning(disable : 4244)
#endif #endif
// 这个头文件包含了 mystl 的一系列算法 // #ifndef MYTINYSTL_ALGO_H_ 和 #define MYTINYSTL_ALGO_H_ 是头文件保护,防止重复包含。
//#ifdef _MSC_VER 是 Microsoft Visual C++ 编译器的特定代码,#pragma warning(push) 和 #pragma warning(disable : 4244) 用于禁用特定的编译器警告(这里是 4244 警告,通常与类型转换相关)。
#include <cstddef> #include <cstddef>
#include <ctime> #include <ctime>
@ -16,6 +22,10 @@
#include "heap_algo.h" #include "heap_algo.h"
#include "functional.h" #include "functional.h"
//<cstddef> 和 <ctime> 是标准库头文件,分别用于定义 size_t 类型和时间相关函数。
//"algobase.h"、"memory.h"、"heap_algo.h"、"functional.h" 是 mystl 内部的头文件,分别提供了基础算法、内存管理、堆算法和函数对象相关的功能。
namespace mystl namespace mystl
{ {
@ -2726,6 +2736,85 @@ ForwardIter unique(ForwardIter first, ForwardIter last)
return mystl::unique_copy(first, last, first); return mystl::unique_copy(first, last, first);
} }
//4. 算法实现
/*接下来的代码实现了大量的算法,每个算法都有详细的注释。以下是一些关键算法的简要说明:
4.1 all_ofany_ofnone_of
all_of
any_of
none_of
4.2 countcount_if
count
count_if
4.3 findfind_iffind_if_not
find
find_if
find_if_not
4.4 searchsearch_n
search
search_n n
4.5 lower_boundupper_boundbinary_search
lower_bound
upper_bound
binary_search
4.6 sortpartial_sortnth_element
sort
partial_sort
nth_element 使 n
4.7 mergeinplace_merge
merge
inplace_merge
4.8 uniqueunique_copy
unique
unique_copy
4.9 partitionpartition_copy
partition
partition_copy
4.10 reversereverse_copy
reverse
reverse_copy
4.11 random_shuffle
random_shuffle
4.12 rotaterotate_copy
rotate
rotate_copy
4.13 is_permutation
is_permutation
4.14 next_permutationprev_permutation
next_permutation
prev_permutation
*/
// 重载版本使用函数对象 comp 代替比较操作 // 重载版本使用函数对象 comp 代替比较操作
template <class ForwardIter, class Compared> template <class ForwardIter, class Compared>
ForwardIter unique(ForwardIter first, ForwardIter last, Compared comp) ForwardIter unique(ForwardIter first, ForwardIter last, Compared comp)

Loading…
Cancel
Save