队列:一个先进先出的数据结构,就像排队,先来的先办理。
=======================
头文件
#include <queue.h>
1.得到第一个元素
TYPE &front();
2.得到最后一个元素
TYPE &back();
3.判断队列是否为空
bool empty();
4.删除队列的首元素
void pop();
5.往队列加入一个元素
void push(cout TYPE &val);
6.返回队列个数
size_type size();
=================================================
eg:
#include <queue.h>
#include <iostream.h>
int main()
{
queue<int> q;
for(int i = 0; i< 10 ;i++)
{
q.push(i);
}
cout << "the queue size is " << q.size() << endl;
cout << "the head is " << q.front() << endl;
cout << "the end is " << q.back() << endl;
cout << "Is empty " << q.empty() << endl;
while(!q.empty())
{
cout << q.front() << endl;
q.pop();
}
}
本文介绍了队列作为先进先出数据结构的应用,并通过C++头文件提供了队列的基本操作,包括获取首尾元素、判断空队列、删除首元素及添加元素等。通过示例代码演示了如何使用队列进行数据处理。
1222

被折叠的 条评论
为什么被折叠?



