要求是在链表中输入教室的信息,但是程序输出有错误,帮我看看,拜托啦
#include <iostream>#include <string.h>
#include <stdlib.h>
using namespace std;
template <class C>
struct Node
{
C name;
C number;
Node<C> *next;
};
template <class C>
class croom
{
public :
croom();
private :
Node <C> *first;
Node <C> *p,*s;
};
template <class C>
croom<C>::croom()
{
int n;
C name1,number1;
cout<<"请输入总教室数";
cin>>n;
cin.ignore(cin.rdbuf()->in_avail());
p=NULL;
for(int i=1;i<=n;i++)
{
s=new Node<C>;
cout<<"请输入教学楼名称";
//fflush(stdin);
cin>>name1;
cin.ignore(cin.rdbuf()->in_avail());
cout<<endl;
s->name=name1;
cout<<"请输入教室编号";
//fflush(stdin);
cin>>number1;
cin.ignore(cin.rdbuf()->in_avail());
cout<<endl;
s->number=number1;
s->next=NULL;
//头节点直接插入。
if(p){
p->next=s;
p=p->next;
}
else
{
first=s;
p=s;
}
}
}
int main()
{
croom<char>croom;
return 0;
}