荔园在线
荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀
[回到开始]
[上一篇][下一篇]
发信人: huhaiming (一生只爱她), 信区: Program
标 题: 链式队列
发信站: 荔园晨风BBS站 (Thu May 8 21:56:45 2003), 站内信件
同样,自己需要改成类的,自己做
#include <iostream.h>
#include <iomanip.h>
struct Node{
int data;
Node * link;
};
Node * head;
Node * tail;
void EnQueue (int x)
{
Node *q;
q=new Node;
q->data=x;
tail->link=q;
tail=q;
cout<<q->data;
}
int DeQueue()
{
Node *p;
int temp;
p=head;
head=p->link;
temp=head->data;
delete p;
return temp;
}
int Empty()
{
return head==tail;
cout<<"The queue is empty!\n"<<endl;
}
void main()
{
head=new Node;
tail=head;
for(int i=0;i<6;i++)
EnQueue(i);
for (int k=0;k<7;k++)
{
if(Empty())
cout<<"The queue is empty!\n"<<endl;
else
cout<<DeQueue()<< "is out!\n"<<endl;
}
}
--
菩提本无树,明镜亦非台
本来无一物,何处惹尘埃
※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.0.200]
[回到开始]
[上一篇][下一篇]
荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店