实验QStack的先进后出和 QQueue 的先进先出
QStack、QQueue
#include <QCoreApplication>
#include <QDebug>
#include <QStack>
#include <QQueue>
//栈的使用 后进先出
void QStackPrint()
{
QStack<int> stack;
stack.push(10);
stack.push(20);
stack.push(30);
while (!stack.isEmpty())
{
qDebug()<<stack.pop()<<Qt::endl;
}
}
//队列的使用 先进先出
void QQueuePrint()
{
QQueue<int> queue;
queue.enqueue(10);
queue.enqueue(20);
queue.enqueue(30);
while(!queue.isEmpty())
{
qDebug()<<queue.dequeue()<<Qt::endl;
}
}
int main(int argc, char *argv[])
{
QCoreApplication a0(argc, argv);
QStackPrint();
qDebug()<<"--------------------";
QQueuePrint();
qDebug()<<"end!";
return a0.exec();
}
运行结果
30
20
10
--------------------
10
20
30
end!