题解 | #迭代器遍历set#

迭代器遍历set

https://www.nowcoder.com/practice/7e57c0f7af86429db20c70053f23ea96

#include<bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
    set<int>s;
    // write your code here......
    int a;
    while (cin >> a) {
        s.insert(a);
    }

    set<int>::iterator iter = s.begin();
    while (iter != s.end()) {
        cout << *iter << " ";
        iter++;
    }

	cout<<endl;

    while (iter != s.end()) {
        iter--;
        cout << *iter << " ";
    }
	
	cout<<endl;

    return 0;
}

全部评论

相关推荐

神哥不得了:神哥来啦~ JVm可以写在juc的下面,另外的话,项目亮点的话再重新用star法则再改一遍,其余的东西写的还是非常的好的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务