Little things related to the STL

multiset
/ balanced binary tree lookup deleting inserted data
complexity is n-log
/
#include <stdio.h>
#include
#include
#include
the using namespace STD;
int main () {
multiset ST; multiset // define a variable, which data can be automatic sorting
int A [. 7] 26,3,13,2,53,23,343 = {};
int I;
for (I = 0; I <. 7; I ++) {// the a [] elements in the content to ST
ST .insert (a [I]);
}
multiset iterator :: P; // iterators to traverse used, like pointers
for (P = st.begin (); P = st.end ();! P ++) { / /st.begin point header element
//st.end point after the last element of the
printf ( "% d", * p); // read the content of
}
the printf ( "\ n-");
multiset :: Iterator J; // for finding
j = st.find (20); // find a number, returns an iterator
if (j == st.end ()) ( "no num \ n") printf;
else printf("%d\n",*j);

st.insert(20);            //插入 
for(p=st.begin();p!=st.end();p++){  //st.begin指向头元素
                                    //st.end指向最后一个元素的后面 
	printf("%d ",*p);               //读内容 
}
printf("\n");

st.erase(13);        //删除
for(p=st.begin();p!=st.end();p++){  //st.begin指向头元素
                                    //st.end指向最后一个元素的后面 
 	printf("%d ",*p);               //读内容 
}
return 0;

}

Published 22 original articles · won praise 1 · views 1068

Guess you like

Origin blog.csdn.net/Doro_/article/details/94628998