#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
#define UNIT_MAX_SIZE 100
#define increasize 10
//自定义类<在模板中用的数据类型自定义>
class student
{
int sno;
string name;
public:
student(int S=1,string N="张三"){
sno=S;name=N;
}
~student(){ }
student& operator=(const student& s)
{
sno=s.sno;
name=s.name;
return *this;
}
friend int operator==(const student& s1,const student& s2)
{
if(s1.name==s2.name&&s1.sno==s1.sno)
return 1;
else
return 0;
}
friend ostream& operator<<(ostream &os,const student& s)
{
os<<s.sno<<"_"<<s.name;
return os;
}
friend istream& operator>>(istream &is,student& s)
{
is>>s.sno>>s.name;
return is;
}
};
//抽象类,使用多态,作访问接口——表述可能不是很清楚
class Base
{
private:
static int num;
public:
virtual ~Base(){}
virtual void display()=0;
int getnum(){
return num;
}
};
int Base::num=0;//统计建表数目
//顺序表类(有各种操作,不清楚的可以留言)
template<class T>
class sqlist:public Base
{
private:
T *elem;
int length;
int listsize,inc;
public:
sqlist(const sqlist& s)
{
length=s.length;
listsize=s.listsize;
inc=s.inc;
elem=new T[length];
for(int i=0;i<length;i++)
elem[i]=s.elem[i];
num++;
}
sqlist()
{
elem=new T[UNIT_MAX_SIZE];
try{
if(!elem) throw int(1);
}
catch(int i){
cout<<"创建失败!"<<i<<endl;
}
length=0;
listsize=UNIT_MAX_SIZE;
num++;
}
~sqlist(){delete []elem;num--;}
void display()
{
for(int i=0;i<length;i++)
{
cout<<elem[i];
cout<<"、";
}
cout<<endl;
}
int Find(T Elem)
{
for(int i=0;i<length;i++)
{
if(elem[i]==Elem)
return i+1;
}
return 0;
}
int Insert(const T& Elem,int ins