您的位置:首页 > 产品设计 > UI/UE

STL之set,queue,stack常用方法

2008-05-08 17:17 218 查看

#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>::iterator it=st.begin(); it!=st.end(); it++)


cout << " "<< *it;


cout << endl;


}






void run()...{


cout << "set ";


set <int> st;




for(int i=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(int j=0;j<N;j++)


q.push(j+1);




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




while(q.empty()==false)




...{


int t=q.front();


cout << " "<< t ;


q.pop();


}




cout << endl;




cout << " stack ";


stack <int> s;




for(int k=0;k<N;k++)


s.push(k+1);




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




while(s.empty()==false)




...{


int t=s.top();


cout << " "<< t ;


s.pop();


}




cout << endl;


}






int main()...{


run();


return 0;


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: