首页 > 电脑
c++语言队列怎么输出
更新时间2018-10-31 12:26:51
C++ ,语言队列输出代码如下:
#include<iostream>
using namespace std;
struct list
{
int date;
list *next;
};
class Quene
{
public:
Quene()
{
head=end=NULL;
}
void enquene(int x);
int dequene();
private:
list *head;
list *end;
}
void Quene::enquene(int x)
{
list *newnode = new list;
newnode->date = x;
newnode->next = NULL;
if(end = NULL)
{
head = end = newnode;
}
else
{
end->next = newnode;
end = newnode;
}
}
int Quene::dequene()
{
list *temp;
int value;
value = head->date;
temp = head;
head = head->next;
delete temp;
return value;
}
int main()
{
Quene A;
int a[]={1,2,3,4,5};
cout<<"入队顺序"<<endl;
for(int i=0;i<5;i++)
{
cout<<a[i]<<endl;
A.enquene(a[i]);
}
cout<<endl<<"出队顺序";
for(int i=0;i<5;i++)
{
cout<<A.dequene()<<""<<endl;
}
return 0;
}