用队列接受并且显示,麻烦大大帮下忙,现在能接受2个数,但是只能显示第一个的,我要怎样做才能显示出2个来,搞了7.8个小时了,郁闷得很
#include <iostream>
#include <string>
using namespace std;
class node
{
private:
string data;
string name;
public:
node *Next;
void add_data(const string &d);
string disp_data();
void disp()
{
cout<<"\nCustomer data :\t"<<data;
cout<<"\nName :\t"<<name;
}
};
void node::add_data(const string &d)
{
data=d;
cout<<"\nEnter Customer Name\t";
getline(cin,name);
}
string node::disp_data()
{
return disp();
}
class queClass
{
node *FRONT, *REAR;
public:
queClass(void);
void add_node(string &d);
bool del_node();
};
queClass::queClass()
{
FRONT=NULL;
REAR=NULL;
}
void queClass::add_node(string &d)
{
node *Fresh;
Fresh = new node;
Fresh->add_data(d);
Fresh->Next = NULL;
if(FRONT==NULL)
{
FRONT=Fresh;
REAR=Fresh;
}
else
{
REAR->Next=Fresh;
REAR=Fresh;
}
}
bool queClass::del_node()
{
node *temp;
int ctr=1;
if (FRONT==NULL)
return false;
while(FRONT!=NULL)
{
temp=FRONT;
FRONT=FRONT->Next;
cout<<"Candidate\t"<<ctr<<"\t is "<<temp->disp_data()<<endl;
ctr++;
delete temp;
}
return true;
}
int main()
{
queClass q1;
string val;
char choice='y';
while(choice=='y')
{
cout<<"Are there any more people in Queue (y/n)?";
cin>>choice;
if(choice == 'n')
break;
cout<<"\n\n Enter name of Person in the Queue\n\n";
cin.ignore();
getline(cin,val);
q1.add_node(val);
}
cout<<"The Order of Interview Time on First-cum-first basis of all the ,candidates is as follows:\n";
if (q1.del_node()==false)
cout<<"No candidates for Interview\n";
system("PAUSE");
}