C++ 前向列表操作函数

2024年8月28日 | 阅读 4 分钟

本文旨在介绍 C++ 编程语言的标准模板库,我们将从中看到操作函数的使用。

由于 C++ STL 如海洋般浩瀚,这里我们讨论了几个关键函数,如 merge()、operator"="、sort()、unique()、reverse() 和 swap 运算符,并附上了它们的示例代码和输出。

重要函数 1:merge() 和运算符 "=. "

C++ 代码

输出

displaying the content have at the 2nd forward list after performing the copy operations we have are: 51 52 53 
showing the content have at the forwarding list after completing the merge operations we have are: 51 51 52 52 53 53

重要函数 2:sort() 和 Unique()

C++ 代码

输出

displaying the content, we have on the forward list. After performing the sort operations, we have 51 51 72 93 93 93 
displaying the content, we have on the forward list. After completing the unique functions, we have 51 72 93

重要函数 3:swap()

C++ 代码

输出

The contents of the forwarding list after reversing are: 73 62 31 
The contents of 1st forward list before swapping are: 73 62 31 
The contents of the 2nd forward list before changing are: 54 65 86 
range of 1st forward list after changing are: 54 65 86 
range of 2nd forward list after changing is: 73 62 31

下一个主题C/C++ 中的断言