⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prg9_2.cpp

📁 这是数据结构和算法的国外经典书籍.清华大学出版社出版的<数据结构C++语言描述-应用模板库STL>陈君 译 英文名称是Data Structures with C++ Using STL.
💻 CPP
字号:
// File: prg9_2.cpp
// the program tests the linkedQueue class by pushing
// the values in an array onto a queue. by using front()
// followed by pop(), the programs displays the contents
// of the queue as it empties it. when the queue is empty,
// a call to pop() causes the underflowError exception.
// after catching the exception and displaying an error
// message, the program terminates 

#include <iostream>

#include "d_lqueue.h"

using namespace std;

int main()
{
	// declare an integer array and compute its size
	int arr[] = {6, 9, 2, 5}, i;
	int arrSize = sizeof(arr)/sizeof(int);

	// declare an empty queue of integer elements
	linkedQueue<int> q;

	// insert the array elements in q and output their value
	for (i = 0; i < arrSize; i++)
		q.push(arr[i]);

	// display the resulting size of the queue
	cout << "Queue size is " << q.size() << endl;

	// clear the queue
	while (!q.empty())
	{
		// display the element at the front and then
		// erase it from the queue
		cout << q.front() << "  ";
		q.pop();
	}
	cout << endl;

	// handle the underflowError exception thrown by a call to pop()
	try
	{
		q.pop();
	}
	catch (const underflowError& ue)
	{
		cout << ue.what() << endl;
	}

	return 0;
}

/*
Run:

Queue size is 4
6  9  2  5
queue pop(): empty queue
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -