//头文件定义结构体和类
#ifndef tongxunlu_h
#define tongxunlu_h
struct Bir
{
int year,month,day;
};
struct Student
{
char name;
char sex;
char address;
int code;
int age;
int number;
int QQ;
char wechat;
Bir birthady;
};
struct Node
{
Student data;
Node *next;
};
class StudentList
{
public:
StudentList();
StudentList(Student a[],int n);
//~StudentList();
int Length();
Student Get(int i);
int Locate(Student x);
void Insert(int i,Student x);
Student Delete(int i);
void PrintList();
private:
Node *first;
};
#endif
//定义成员函数
#include
using namespace std;
#include "tongxunlu.h"
StudentList::StudentList()
{
first = new Node;
first->next=NULL;//只有一个头结点,没有元素
}
StudentList::StudentList(Student a[],int n)
{
first=new Node;//头结点
first->next=NULL;
for(int i=0;i
{
Node *s=new Node;s->data=a[i];//头插法
s->next=first->next;first->next=s;
}
}
int StudentList::Length()
{
Node *p=first->next;//p初始化为指向首元结点
int count=0;
while(p!=NULL)
{
p=p->next;
count++;
}
return count;
}
Student StudentList::Get(int i)
{
Node *p=first->next;
int count=1;
while(p!=NULL&&count
{
p=p->next;
count++;
}
if(p==NULL)throw"位置";
else return p->data;
}
int StudentList::Locate(Student x)
{
Node *p=first->next;
int count=1;
while(p!=NULL)
{
if(p->data==x)
return count;
p=p->next;
count++;
}
return 0;
}
void StudentList::Insert(int i,Student x)
{
Node *p=first;
int count=0;
while(p!=NULL&&count
{
p=p->next;
count++;
}
if(p==NULL)throw"位置";
else
{
s=new Node;s->data=x;
s->next=p->next;p->next=s;
}
}
Student StudentList::Delete(int i)
{
Node *p=first;
int count=0;
while(p!=NULL&&count
{
p=p->next;
count++;
}
if(p==NULL||p->next==NULL)//结点p不存在或p的后继结点不存在
throw"位置";
else
{
Node *q=p->next;
Student x=q->data;//暂存被删结点
p->next=q->next;//摘链
delete q;
return x;
}
}
void StudentList::PrintList()
{
Node *p=first->next;
while(p!=NULL)
{
cout<data;
p=p->next;
}
}
//主函数
#include
using namespace std;
#include "tongxunlu.cpp"
int main()
{
Student a[5];
int i;
cout<<"请输入5位学生的信息:"
for(i=0;i
cin>>a[i];
StudentList stu(a,5);
stu.PrintList();
return 0;
}
运行发现错误是could not deduce template arguement for'const class std::allocator<_Ty>& from 'struct Student'
看不懂是什么意思,求教!