C++day6(多重继承、多级继承、虚继承、虚函数、多态、模板)--顺序栈模板、循环队列模板

顺序栈的模板类:

#include 

using namespace std;

template 

class Stacklist
{
protected:
    T *data;
    int MAXSIZE;
    int top;
public:
    Stacklist():MAXSIZE(10),top(-1)
    {
        data=new T[MAXSIZE];
        cout<<"Stacklist::无参构造"<top)
            return;
        cout<<"sub位置的元素:"<s1(10);
    int c;
    for(int i=0;i<5;i++)
    {
        cin>>c;
        s1.push(c);
    }
    s1.show();
    s1.stacklist_size();
    s1.stacklist_top();
    s1.stacklist_sub(3);
    s1.stacklist_delete();
    s1.show();
    Stacklists2;
    s2.push('c');
    s2.show();
    Stacklists3;
    s3=s2;
    s3.show();
    return 0;
}

 C++day6(多重继承、多级继承、虚继承、虚函数、多态、模板)--顺序栈模板、循环队列模板_第1张图片

  循环顺序队列的模板类:

#include 

using namespace std;

template 
class Queue
{
protected:
    int MAXSIZE;
    T *data;
    int front;    //队头
    int rear;     //队尾
public:
    Queue():MAXSIZE(10),front(0),rear(0)
    {
        data=new T[MAXSIZE];
        cout<<"Queue::无参构造"<MAXSIZE=other.MAXSIZE;
            this->data=new T(*(other.data));
            this->front=other.front;
            this->rear=other.rear;
        }
        cout<<"Queue::拷贝赋值"<s1(10);
    int m;
    for(int i=0;i<5;i++)
    {
        cin>>m;
        s1.push(m);
    }
    s1.show();
    s1.queue_first();
    s1.queue_last();
    s1.size();
    s1.queue_delete();
    s1.show();
    Queues2;
    s2.push('p');
    s2.show();
    return 0;
}

你可能感兴趣的:(c++,算法,开发语言)