STL基础4:deque

时间:2021-12-17 16:20:24
#include <iostream>
#include <queue>
#include <string> using namespace std;
#define N_K 10 struct Data_s{
int number;
char name[];
}; typedef struct Data_s Data_t; void makeData(Data_t *d)
{
int i;
for (i=;i<N_K;i++)
{
d[i].number = i;
sprintf(d[i].name,"name %02d",i);
}
} template<typename T>
struct display{
void operator()(const T &x)const
{
cout<<x.number<<" "<<x.name<<endl;
}
}; int main()
{
Data_t d[N_K];
deque<Data_t> dd;
int i;
makeData(d);
for (i=;i<N_K;i++)
{
dd.push_back(d[i]); }
cout<<"size "<<dd.size()<<endl; cout<<"1.first "<<dd[].number<<endl; dd.pop_front();
cout<<"2.first "<<dd[].number<<endl;
dd.pop_front();
dd.pop_front();
dd.pop_front();
for (i=;i<N_K;i++)
{
dd.push_back(d[i]); }
cout<<"size "<<dd.size()<<endl; for_each(dd.begin(),dd.end(),display<Data_t>()); return ;
}