队列的链表实现

/*
 * queue_3.cpp
 *
 *  Created on: 2013年8月2日
 *      Author: 黄俊东
 *      目标章泽天。。。加油。。。。。
 *
 */

#include <iostream>
#include "list_2.h"

using namespace std;
typedef int T;

class Queue {
	List l;
public:
	Queue& push(const T& d) {
		l.push_back(d);
		return *this;
	}

	T pop() {
		T t = l.front();
		l.erase(0);
		return t;
	}

	const T& front() {
		return l.front();

	}

	const T& back() {
		return l.back();
	}

	int size() {
		return l.size();
	}

	void clear() {
		l.clear();
	}

	bool empty() {
		return l.empty();

	}

	bool full() {
		return false;
	}
};
int main() {

	Queue q;
	try {
		q.push(1).push(2).push(3).push(4).push(5);

		cout << q.pop() << endl;
		cout << q.pop() << endl;

		q.push(6).push(7).push(8);
	} catch (const char* e) {

		cout << "异常:" << e << endl;
	}

	while (!q.empty()) {
		cout << q.pop() << endl;
	}
}



原文地址:https://www.cnblogs.com/dyllove98/p/3235255.html