#include <iostream.h>
typedef struct s
{
char ch;
s *next;
}ss;
typedef struct
{
ss *front;
ss *rear;
}queue;
class Queue
{
public:
Queue(); //构造
Queue(Queue &Q); //拷贝构造
~Queue(); //析构
void print(); //显示
void in(); //进队
void out(); //出队
private:
queue *point;
};
Queue::Queue()
{
ss * node;
node = new ss;
point= new queue;
node->next = NULL;
point->front=node;
point->rear = node;
}
Queue::~Queue()
{
while(point->front)
{
point->rear = point->front->next;
delete (point->front);
point->front=point->rear;
}
delete point;
}
Queue::Queue(Queue &Q) //深拷贝
{
ss *p , *node ;
node = new ss;
point= new queue;
node->next = NULL;
point->front = point->rear = node;
p = (Q.point)->front->next;
for( ; p!=NULL ; p = p->next)
{
node = new ss;
node->ch = p->ch;
node->next = NULL;
point->rear->next = node;
point->rear = node;
}
}
void Queue::in()
{
ss *node;
char m;
node = new ss;
cout<<"请输入进队的字母:";
cin>>m;
node->ch=m;
node->next = NULL;
point->rear->next = node;
point->rear = node;
}
void Queue::print()
{
ss *p;
p=point->front->next;
while(p->next)
{
cout<<p->ch<<"<-";
p=p->next;
}
cout<<p->ch;
}
void Queue::out()
{
ss *node;
node = point->front->next;
cout<<node->ch<<"出队"<<endl;
point->front->next=node->next;
if(point->rear==node)
point->rear=point->front;
delete node;
}
int main()
{
Queue Q1;
int i;
for(i=0;i<5;i++)
Q1.in();
Queue Q2=Q1;
cout<<" 队Q1已经拷贝到Q2中"<<endl;
cout<<"对于Q1,";
Q1.in();
cout<<"Q2: "; Q2.out();
cout<<"Q1: "; Q1.print();
cout<<endl;
cout<<"Q2: "; Q2.print();
cout<<endl;
return 1;
}
typedef struct s
{
char ch;
s *next;
}ss;
typedef struct
{
ss *front;
ss *rear;
}queue;
class Queue
{
public:
Queue(); //构造
Queue(Queue &Q); //拷贝构造
~Queue(); //析构
void print(); //显示
void in(); //进队
void out(); //出队
private:
queue *point;
};
Queue::Queue()
{
ss * node;
node = new ss;
point= new queue;
node->next = NULL;
point->front=node;
point->rear = node;
}
Queue::~Queue()
{
while(point->front)
{
point->rear = point->front->next;
delete (point->front);
point->front=point->rear;
}
delete point;
}
Queue::Queue(Queue &Q) //深拷贝
{
ss *p , *node ;
node = new ss;
point= new queue;
node->next = NULL;
point->front = point->rear = node;
p = (Q.point)->front->next;
for( ; p!=NULL ; p = p->next)
{
node = new ss;
node->ch = p->ch;
node->next = NULL;
point->rear->next = node;
point->rear = node;
}
}
void Queue::in()
{
ss *node;
char m;
node = new ss;
cout<<"请输入进队的字母:";
cin>>m;
node->ch=m;
node->next = NULL;
point->rear->next = node;
point->rear = node;
}
void Queue::print()
{
ss *p;
p=point->front->next;
while(p->next)
{
cout<<p->ch<<"<-";
p=p->next;
}
cout<<p->ch;
}
void Queue::out()
{
ss *node;
node = point->front->next;
cout<<node->ch<<"出队"<<endl;
point->front->next=node->next;
if(point->rear==node)
point->rear=point->front;
delete node;
}
int main()
{
Queue Q1;
int i;
for(i=0;i<5;i++)
Q1.in();
Queue Q2=Q1;
cout<<" 队Q1已经拷贝到Q2中"<<endl;
cout<<"对于Q1,";
Q1.in();
cout<<"Q2: "; Q2.out();
cout<<"Q1: "; Q1.print();
cout<<endl;
cout<<"Q2: "; Q2.print();
cout<<endl;
return 1;
}