动态数组
srand(time(0));
std::vector<int> qwq;
for(int i = 1;i <= 10;++i)
qwq.push_back(rand()%100);
int n = qwq.size();
for(int i = 1;i <= n;++i)
std::cout<< qwq[i-1] << " ";
std::cout << "\n";
sort(qwq.begin(),qwq.end());
for(int i = 1;i <= n;++i)
std::cout<< qwq[i-1] << " ";
栈
srand(time(0));
std::stack<int> qwq;
for(int i = 1;i <= 10;++i)
{
int x = rand()%100;
std::cout << x << " ";
qwq.push(x);
}
std::cout << "\n";
int n = qwq.size();
for(int i = 1;i <= n;++i)
{
std:: cout << qwq.top() <<" ";
qwq.pop();
}
队列
srand(time(0));
std::queue<int> qwq;
for(int i = 1;i <= 10;++i)
qwq.push(rand()%100);
int n = qwq.size();
for(int i = 1;i <= n;++i)
{
std::cout << qwq.front() << " ";
qwq.pop();
}
if(qwq.empty()) std::cout << "\n队列已经清空!";
优先队列
//1. 大根堆
srand(time(0));
std::priority_queue<int> qwq;
for(int i = 1;i <= 10;++i)
qwq.push(rand()%100);
int n = qwq.size();
for(int i = 1;i <= n;++i)
{
std::cout << qwq.top() << " ";
qwq.pop();
}
std::cout << std::endl;
//2. 小根堆
std::priority_queue<int,std::vector<int>,std::greater<int> > qaq;
for(int i = 1;i <= 10;++i)
qaq.push(rand()%100);
n = qaq.size();
for(int i = 1;i <= n;++i)
{
std::cout << qaq.top() << " ";
qaq.pop();
}