在"s"C++之前缺少模板参数



我正在做一个分配,但不确定我的问题是

这是我的作业

说明您有两个部分。这些零件是相关的,但其实施不同。为了更好地理解作业本身,返回书籍,幻灯片,笔记等可能会很有帮助,并执行基于数组的基于数组和链接的基于列表的堆栈以及堆栈ADT的实现。

第一部分堆栈的一种广泛使用是提供从许多不同应用程序中熟悉的撤消操作。尽管可以使用无限制的堆栈(只要记忆允许就可以不断增长(来实施对撤消的支持,但许多应用程序仅提供对这种撤消历史记录的有限支持。换句话说,堆栈是固定容量的。当这样的堆栈已满并调用推动而不是抛出例外时,更典型的方法是接受顶部的推送元素,同时从堆栈的底部删除最古老的元素以使空间。这被称为"泄漏"。请注意,这并不意味着ADT揭示了一种可以直接从底部删除的方法。仅当堆栈变满时才能执行。对于这一部分,您将使用一些基于数组的实现来实现此类LeakyStack抽象。请注意,您必须创建一个泄漏的堆栈接口,然后使用C :运算符在您的LeakyArrayStack实现中实现该接口(使用公共继承(。请参阅分配说明末尾附近指定的接口。

第二部分重复第I部分,但是使用单个链接列表,而不是用于实际数据存储的数组,并允许将最大容量指定为构造函数的参数。

注意:•基于数组的基于数组和基于链接列表的泄漏堆栈均应使用以下指定的相同的泄漏stackInterface。请记住 - 这是一个LeakyStack ADT。它指定了泄漏堆栈的作用,而不是如何做。因此,为了提供实现,该接口不应有所不同。•在这两个部分中使用公共继承•您应该首先写一个单链接列表,然后再尝试进行II部分O,然后使用coantment(聚合或构图,a has-a关系(来实现第II部分

我必须使用图片中的接口

这是我的代码

    #include <iostream>
     #ifndef LEAKYStacksINTERFACE
     #define LEAKYStacksINTERFACE
      #define cap 10
     using namespace std;

     template<typename ItemType>
     class LeakyStacksInterface
      {  public:
      //returns whether Stacks is empty or not
     virtual bool isEmpty() const = 0;
     //adds a new entry to the top of the Stacks
     //if the Stacks is full, the bottom item is removed
     //or "leaked" first, and then the new item is set to the top
     //---> If the Stacks was full when the push was attempted, return false
     //---> If the Stacks was not full when the push was attempted, return true
    virtual bool push(const ItemType& newEntry) = 0;
     //remove the top item
     //if the Stacks is empty, return false to indicate failure
     virtual bool pop() = 0;
      //return a copy of the top of the Stacks
   virtual ItemType peek() const = 0;
  //destroys the Stacks and frees up memory
   //that was allocated
    // virtual ~StacksInterface() {}
   };
template<typename ItemType>
struct node
{
    int data;
    struct node *next;
};


template<typename ItemType>
class Stacks : public LeakyStacksInterface<ItemType>
{
    struct node<ItemType> *top;
    public:
            int size;
            ItemType *myArray;
    Stacks()
    {
        top=NULL;
        size = 0;
        myArray = new ItemType[cap];
    }
    ~Stacks() {
        size = 0;
    }
    public:
   // pure virtual function providing interface framework.
    bool isEmpty() const {
        return(size == 0);
    }
 bool push(const ItemType& newEntry) {
        if(size == cap) {
            for(int i = 0; i < size-1; i++) {
                myArray[i] = myArray[i+1];
            }
            myArray[size-1] = newEntry;
            return false;
        }
 }
    ItemType peek() const {
        return myArray[size-1];
    }
     void display()
   {
      cout<<"Stacks: [ ";
      for(int i=size-1; i>=0; i--)
      {
         cout<<myArray[i]<<" ";
      }
      cout<<" ] "<<endl;
   }
};

int main()
{
    Stacks s;
   int choice;
    while(1)
    {
        cout<<"n-----------------------------------------------------------";
        cout<<"nttSTACK USING LINKED LISTnn";
        cout<<"1:PUSHn2:POPn3:DISPLAY STACKn4:EXIT";
        cout<<"nEnter your choice(1-4): ";
        cin>>choice;
        switch(choice)
        {
            case 1:
                s.push();
                break;
            case 2:
                s.pop();
                break;
            case 3:
                s.show();
                break;
            case 4:
                return 0;
                break;
            default:
                cout<<"Please enter correct choice(1-4)!!";
                break;
        }
    }
    return 0;
}
#endif

这是我的错误:错误:" S"之前丢失模板参数错误:预期';'在" S"之前错误:" S"在此范围中没有阐述

请帮忙!谢谢!

接口图片

Stacks是类模板,因此要使用它,您必须提供模板参数,例如

Stacks<int> s;

最新更新