2020.8.17
二叉树搜索
#include <iostream>
#include <set> //int , double
#include <map> //pair<>
#include <string>
using namespace std;
map<string, int> word_count;
set<int> s;
int main(){
//插入
s.insert(10);
word_count.insert(make_pair(string("hello"), 1));
word_count["hello"] = 1;
//查找
set<int>::iterator iter;
iter = s.find(10);
if(iter == s.end()){
cout<<"Not Found"<<endl;
}
cout<<word_count["hello"] <<endl;
//删除
s.erase(10);
s.erase(1);
word_count.erase("hello");//key:value 键值对
//遍历
for(iter = s.begin(); iter!=s.end(); iter++) {
cout<<*iter<<" ";
}
for(map<string, int> it = word_count.begin(); it!=word_count.end(); it++){
cout<<(*it).first<<" "<<(*it).second<<endl;
cout<<it->first<<" "<<it->second<<endl;
}
}