在私有继承LinkedStack的QueueAsAStack上实现isempty函数

时间:2018-11-20 01:21:20

标签: c++

对于此项目,我们需要创建一个链接栈的队列。我在为此队列实现isEmpty函数时遇到麻烦。

QueueAsAStack.h

#ifndef QUEUE_AS_A_STACK
#define QUEUE_AS_A_STACK

#include "QueueInterface.h"
#include "LinkedStack.cpp"



template<class ItemType>

class QueueAsAStack : public QueueInterface <ItemType>, private LinkedStack <ItemType> {

public:



    bool isEmpty() const;

    bool enqueue(const ItemType&);

    bool dequeue();

    ItemType peekFront() const;

    };



    #endif

QueueAsAStack.cpp

//Function to check if the Queue is empty

 template<class ItemType>

bool QueueAsAStack<ItemType>::isEmpty() const {


return stack->peek()  == 0;

}

任何建议将不胜感激。

1 个答案:

答案 0 :(得分:0)

我认为我们在同一个班上。如果您到任何地方,请告诉我。对于isEmpty,我们在QueueAsAStack的isEmpty方法内部使用了链接堆栈的isEmpty方法,如下所示:“ return LinkedStack :: isEmpty();”。

相关问题