顺序栈的模板类:
#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;
}
循环顺序队列的模板类:
#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;
}