关于c++:HackingC-Learning笔记-Chapter7Standard-Library-–-Part-2

2次阅读

共计 2174 个字符,预计需要花费 6 分钟才能阅读完成。

规范库 Range Copy 算法

留神: 必须要保障指标地位有足够的空间 (resize 或者 reserve),规范算法在大多数状况下不能查看指标范畴是否足够大

copy(@beg, @end, @target_begin) -> @target_out 
copy_n(@beg, n, @target_begin) -> @target_out  
copy_backward(@beg, @end, @target_end) -> @target_begin (拷贝到 end 处)
copy_if(@beg, @end, @target,f(O)->bool)->target_end
sample(@beg, @end, @out, n, random_generator) ->out_end (实现采样 -c++17)

Special 迭代器

  • 感觉用途不大哦,除了插入这个 interator

规范库 Sequence Reordering 算法

#shitf Elements 转换元素
1.reserve/reserve_copy 反转
2.rotate/rotate_copy 旋转
    shift_left/shift_right(X 感觉用途不大 c ++20)3.shuffle(@beg, @end,randim_engine) 随机打乱
#sort 排序
1.sort(@begin, @end, compare(o,o)->bool)
2.stable_sort(@begin, @end, compare(o,o)->bool)
//a.sort 是疾速排序实现,因而是不稳固的;stable_sort 是归并排序实现,因而是稳固的;//b. 对于相等的元素 sort 可能扭转程序,stable_sort 保障排序后相等的元素秩序不变
//c. 如果提供了比拟函数,sort 不要求比拟函数的参数被限定为 const,而 stable_sort 则要求参数被限定为 const,否则编译不能通过
3.partial_sort(@begin, n, @end, compare(o,o)->bool) /partial_sort_copy()
    nth_elements(没想到用处)
4.is_sorted(@begin, @end, compare(o,o)->bool) -> true (是否有序)
5.is_sorted_until(@begin, @end, compare(o,o)->bool) -> @sorted_end(返回到哪里之前是有序的)# partition 分区
1.partition(@beg, @end, f(o,o)->bool) ->@ftrue_end 
2.partition_copy(@beg, @end, @ft, @ff, f(O)->bool) -> {@ft_end, @ff_end}
3.stable_partition(@beg, @end, f(o,o)->bool) ->@ftrue_end 
// stable_partition 保障分区后原来的先后顺序不变,而 partition 无奈保障
4.is_partition() -> true
5.partition_point() -> @ftrue_end ( 分区后返回分界点)
## Permutations 排列组合(不晓得利用场景??)1.next_permutation(@beg, @end) -> true 只有下一种排列能够是逻辑上大的,就返回 true
2.prev_permutataion(@beg, @end) -> true 只有上一种排列能够是逻辑上小的,就返回 true
3.is_permutation(@beg, @end, @beg2) -> true if range2 is a permutation of range1

规范库 Element-Wise Range Modifications(批改)

# Filling / Overwriting Ranges 填充改写
1.fill(@beg, @end, value) ->@filled_end  (fill_n)
2.generate(@begin ,@end generator()-> ●) (generator_n)
//generator 能够通过 functors 写入不同的 value,比 fill 性能强,不必循环这么捞的写了
# Changing / Replacing Values 扭转代替
1.transform(@beg, @end, @out, f(O)->■) -> @out_end
2.transform(@beg, @end, @beg2, @out, f(O,△) -> ■) -> @out_end
// 该算法在其余编程语言中也称为 "map"
//target 必须可能承受和 input range 元素一样多的元素
// f 必须没有 side_effect / be stateful , 因为不能保障将 functors 利用于输出元素的程序
3.replace(@beg, @end, old_value, new_value) / replace_if(@beg, @end, condition(O)->bool)
4.replace_copy/replace_copy_if

Removing Elements

Numeric Operations

Sorted Sequence Operations

Binary Heap Operations

Special Containers

Random Numbers

正文完
 0