求一个C++队列算法演示的源程序。。。
来源:百度知道 编辑:UC知道 时间:2024/07/08 02:45:19
#include<iostream>
using namespace std;
typedef struct qnode{
int data;
struct qnode *next;
}qnode,*queueptr;
typedef struct{
queueptr front;
queueptr rear;
}linkqueue;
//建立一个链队列
int initqueue(linkqueue &l) {
qnode *s,*h;
int i,j;
l.front=l.rear=h=(queueptr)malloc(sizeof(qnode)); //作为头结点,不存数据
if(!l.front){cout<<"it is fall to create the linkqueue!"<<endl;return -1;}
cout<<"how many qnode do you need?"<<endl;
cin>>j;
if(!j)cout<<"the linkqueue is empty!"<<endl;
for(i=0;i<j;i++){
s=new qnode;
cin>>s->data;
h->next=s;
h=s;
}
h->next=NULL;
l.rear=h; <