崩坏学园2火焰灼热之灵:高手帮看一下我这个C++怎么不能运行

来源:百度文库 编辑:高考问答 时间:2024/04/29 18:06:12
#include<string.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
enum bool{false,true};

template<class T>
struct quenode
{
T nodedata;
quenode * next;
};
template<class T>
class queue
{
protected:
int quesize;
quenode<T> * head;
quenode<T> * tail;
bool allocateeror;
queue ©(queue &q);
public:
queue();
queue(queue &q)
{head=NULL;tail=NULL;copy(q);}
~queue()
{clearque();}
bool getallocateerror()
{return allocateerror;}
void push(T &);
bool pop(T &);
bool isempty()
{return (quesize==0)? true:false;}
void clearque();
queue &operator=(queue &q)

{copy(q);
return * this;
}
};

template <class T>
queue<T>::queue()
{
quesize=0;
allocateerror=false;
head=NULL;
tail=NULL;
}

template <class T>
queue<T> & queue<T>::copy(queue<T>&que)

{
quenode<T> * p,* q,* r;
if (head) clearque();
quesize=que.quesize;
allocateerror=true;
head=NULL;
tail=NULL;
if (! que.head)
return *this;
head=new quenode<T>;
if(!head)
{
allocateerror=true;
return *this;
}

head->nodedata=que.head->nodedata;

head->next=NULL;
tail=head;
r=NULL;
P=head;
q=que.head->next;
while(q)
{
r=new quenode<T>;
if (!r)
{
allocateerror=true;
return *this;
}
r->nodedata=q->nodedata;
r->next=NULL;
p->next=r;
tail=r;
p=p->next;
q=q->next;
}
return * this;
}

template <class T>
void queue<T>::push(T&x)
{
quenode<T>*p;
p=new quenode<T>;
if (!p)
{
allocateerror=true;
return;
}
p->nodedata=x;
if (tail)
{
p->next=NULL;
tail->next=p;
tail=p;
}
else
{
p->next=NULL;
tail=p;
head=p;
}
quesize++;
}

template <class T>
bool queue<T>::pop(T &x)
{
quenode<T> *p;
if (head)
{
x=head->nodedata;
p=head;
head=head->next;
if (head==NULL)
tail=NULL;
delete p;
quesize--;
return true;
}
return false;
}

template<class T>
void queue<T>::clearque()
{
T p;
allocateerror=false;
while(pop(p));
head=tail=NULL;
}
class student
{
public:
char name[80];
int age;
int sno;
char sex[8];
void assign(char *name,int age,int sno,char *sex)
{
strcpy(student::name,name);
student::age=age;
student::sno=sno;
strcpy(student::sex,sex);
}
void print()
{printf("%10s%6d%10.2f%8s\n",name,age,sno,sex);}
};
void viewque(queue<student>&que)
{
int i=1;
student p;
queue<student>quecopy(que);
void clrscr(void);
while(quecopy.pop(p))
{
//gotoxy(1,i+5);
printf("%2d:",i++);
p.print();
}
}

main()
{
queue<student>que;
student p;
p.assign("zhonglin",23,2123,"male");
que.push(p);
p.assign("wanggaoling",21,2206,"female");
que.push(p);
p.assign("zhangdaling",21,2204,"female");
que.push(p);
p.assign("fanglidiba",22,2205,"female");
que.push(p);
viewque(que);
return 0;
}

//还剩最后一个错误没解决-_-#

#include<string.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

template<class T>
struct quenode
{
T nodedata;
quenode * next;
};
template<class T>
class queue
{
protected:
int quesize;
quenode<T> * head;
quenode<T> * tail;
bool allocateeror;
public:
queue();
queue(queue &q)
{head=NULL;tail=NULL;copy(q);}
~queue()
{clearque();}
bool getallocateerror()
{return allocateerror;}
void push(T &);
bool pop(T &);
bool isempty()
{return (quesize==0)? true:false;}
void clearque();
queue &operator=(queue &q)

{copy(q);
return * this;
}
};

template <class T>
queue<T>::queue()
{
quesize=0;
allocateerror=false;
head=NULL;
tail=NULL;
}

template <class T>
queue<T> & queue<T>::copy(queue<T>&que)

{
quenode<T> * p,* q,* r;
if (head) clearque();
quesize=que.quesize;
allocateerror=true;
head=NULL;
tail=NULL;
if (! que.head)
return *this;
head=new quenode<T>;
if(!head)
{
allocateerror=true;
return *this;
}

head->nodedata=que.head->nodedata;

head->next=NULL;
tail=head;
r=NULL;
P=head;
q=que.head->next;
while(q)
{
r=new quenode<T>;
if (!r)
{
allocateerror=true;
return *this;
}
r->nodedata=q->nodedata;
r->next=NULL;
p->next=r;
tail=r;
p=p->next;
q=q->next;
}
return * this;
}

template <class T>
void queue<T>::push(T&x)
{
quenode<T>*p;
p=new quenode<T>;
if (!p)
{
allocateerror=true;
return;
}
p->nodedata=x;
if (tail)
{
p->next=NULL;
tail->next=p;
tail=p;
}
else
{
p->next=NULL;
tail=p;
head=p;
}
quesize++;
}

template <class T>
bool queue<T>::pop(T &x)
{
quenode<T> *p;
if (head)
{
x=head->nodedata;
p=head;
head=head->next;
if (head==NULL)
tail=NULL;
delete p;
quesize--;
return true;
}
return false;
}

template<class T>
void queue<T>::clearque()
{
T p;
allocateerror=false;
while(pop(p));
head=tail=NULL;
}
class student
{
public:
char name[80];
int age;
int sno;
char sex[8];
void assign(char *name,int age,int sno,char *sex)
{
strcpy(student::name,name);
student::age=age;
student::sno=sno;
strcpy(student::sex,sex);
}
void print()
{printf("%10s%6d%10.2f%8s\n",name,age,sno,sex);}
};
void viewque(queue<student>&que)
{
int i=1;
student p;
queue<student>quecopy(que);
void clrscr(void);
while(quecopy.pop(p))
{
//gotoxy(1,i+5);
printf("%2d:",i++);
p.print();
}
}

main()
{
queue<student>que;
student p;
p.assign("zhonglin",23,2123,"male");
que.push(p);
p.assign("wanggaoling",21,2206,"female");
que.push(p);
p.assign("zhangdaling",21,2204,"female");
que.push(p);
p.assign("fanglidiba",22,2205,"female");
que.push(p);
viewque(que);
return 0;
}