STL之set,queue,stack常用方法

#pragma warning(disable:4786)
#include
< iostream >
#include
< queue >
#include
< stack >
#include
< set >
using namespace std;

const int N = 10 ;

void prtSet( set < int > st) ... {
for(set<int>::iteratorit=st.begin();it!=st.end();it++)
cout
<<""<<*it;
cout
<<endl;
}


void run() ... {
cout
<<"set ";
set<int>st;

for(inti=0;i<N;i++)
st.insert(rand()
%90+10);
prtSet(st);

st.erase(st.begin());
prtSet(st);

cout
<<""<<st.size()<<endl;

st.clear();

cout
<<" queue ";
queue
<int>q;

for(intj=0;j<N;j++)
q.push(j
+1);

cout
<<""<<q.size()<<endl;

while(q.empty()==false)
...{
intt=q.front();
cout
<<""<<t;
q.pop();
}


cout
<<endl;

cout
<<" stack ";
stack
<int>s;

for(intk=0;k<N;k++)
s.push(k
+1);

cout
<<""<<s.size()<<endl;

while(s.empty()==false)
...{
intt=s.top();
cout
<<""<<t;
s.pop();
}


cout
<<endl;
}


int main() ... {
run();
return0;
}

你可能感兴趣的:(Queue)