c++中stl 哈希函数
C ++ STL set :: insert()函数 (C++ STL set::insert() function)
set::insert() function is a predefined function, it is used to insert an element to the set container.
set :: insert()函数是预定义的函数,用于将元素插入到set容器中。
Prototype:
原型:
set<T> st; //declaration
st.insert(T item);
Parameter:
参数:
T item; //T is the data type
Return type: Iterator pointer to the inserted value
返回类型:插入值的迭代器指针
Usage: The function inserts elements to the set.
用法:该函数将元素插入集合。
Time complexity: O(1)
时间复杂度:O(1)
Example:
例:
For a set of integer,
set<int> st;
st.insert(5);
st.insert(4);
set content: //sorted always(ordered)
4
5
Header file to be included:
包含的头文件:
#include <iostream>
#include <set>
OR
#include <bits/stdc++.h>
C++ implementation:
C ++实现:
#include <bits/stdc++.h>
using namespace std;
void printSet(set<int> st){
set<int>:: iterator it;
cout<<"Set contents are:\n";
for(it=st.begin();it!=st.end();it++)
cout<<*it<<" ";
cout<<endl;
}
int main(){
cout<<"Example of insert function\n";
set<int> st;
set<int>:: iterator it;
cout<<"inserting 4\n";
st.insert(4);
cout<<"inserting 6\n";
st.insert(6);
cout<<"inserting 10\n";
st.insert(10);
printSet(st); //printing current set
return 0;
}
Output
输出量
Example of insert function
inserting 4
inserting 6
inserting 10
Set contents are:
4 6 10
翻译自: https://www.includehelp.com/stl/set-insert-function-in-cpp-stl.aspx
c++中stl 哈希函数