求高手帮忙编一个C++程序!!!!!!

来源:百度知道 编辑:UC知道 时间:2024/07/07 13:08:44
用带头结点的链表方式表示队列,其中头指针指向头结点,尾指针指向队列最后一个元素。向队列中插入(入队)若干元素后,按顺序输出队列中元素,试编写完整程序实现此功能。
根本不对啊

满足你,模板实现的。

// FIFO队列的链表实现,类名小写
template <class T>
class queue
{
private:
typedef struct node{
T item;
node *next;
node(const T &x) : item(x), next(NULL) { }
}*link;

link head, tail; // 队头、队尾
void deletelist()
{
for (link t = head; t != NULL; head = t)
{
t = head->next;
delete head;
}
}
public:
queue(size_t size) { head = NULL; } // 忽略传入参数,目的是保持兼容
bool empty() const { return head == NULL; } // 判断队列是否为空
bool full() const { return false; } // 判断队列是否已满,永不满
queue(const queue& rhs)
{
head = NULL;
*this = rhs;
}
queue& operator=(const queue& rhs)
{
if (this == &rhs)
return *this;
deletel