C++ 环状移动
#include <iostream>
#include <list>
int main() {
auto list = std::list<int>{1, 3, 5, 7, 9};
for (auto i = 0; i < 16; i++) {
std::cout << list.front() << std::endl;
list.splice(list.end(), list, list.begin());
}
std::cout << "==============================" << std::endl;
return 0;
}
输出
1
3
5
7
9
1
3
5
7
9
1
3
5
7
9
1
==============================
Process finished with exit code 0
本文展示了一个使用C++标准库中的list实现环状移动的例子。通过不断将列表的第一个元素移动到列表末尾,演示了如何操作双向链表。此过程重复进行了16次,并输出了每次移动后的列表首元素。
331

被折叠的 条评论
为什么被折叠?



