Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cpplings] Add stl programming exercises #531

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

XueSongTap
Copy link
Contributor

What problem were solved in this pull request?

Issue Number: #524

Problem:

Missing C++ stl programming exercises, affecting contributors' understanding and application of C++ STL
Need to enhance the cpplings exercise collection to support the goal of Issue #508

What is changed and how it works?

  • Added sr/cpplings/stl.cpp file, implementing:
    • Basic examples of sequence containers (vector, list)
    • Examples of associative containers (map, set)
    • Examples of unordered containers (unordered_map, unordered_set)
    • Examples of container adapters (stack, queue, priority_queue)
    • Basic usage of iterators with different containers
    • Common algorithms from the STL algorithm library

Other information

  • Run the test case with ./bin/cpplings/stl

@nautaa nautaa self-requested a review March 24, 2025 02:35
// 1. 容器(Containers) - 用于存储数据的模板类,如vector, list, map, set等。
// - 序列容器:vector, list, deque - 以线性方式存储元素
// - 关联容器:map, set, multimap, multiset - 以键值方式存储和快速查找元素
// - 无序容器:unordered_map, unordered_set - 基于哈希表实现的快速查找
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个无序容器也是关联容器嘛?

// - 输入/输出迭代器:用于单向遍历和读/写操作
// - 前向迭代器:支持多次遍历和读写操作
// - 双向迭代器:允许向前和向后遍历
// - 随机访问迭代器:支持随机访问和指针算术
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

指针算术是什么意思

std::cout << std::endl;

// 迭代器算术
auto iterIt = vec.begin();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

变量名统一用下划线隔开吧

std::cout << "===== Algorithm Library Examples =====\n";

std::vector<int> algVec = {5, 2, 8, 1, 9, 3, 7, 4, 6};
std::vector<int> algVec2(9);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里也是

- Update container classification to correctly categorize unordered containers
- Enhance random access iterator description with more detailed explanation
- Standardize variable naming convention to consistent snake_case style
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants