编程实现队列的建立,測长,打印,入队,出队。
#include执行结果:#include #include #include using namespace std;typedef struct student{ int data; struct student *next;}node;typedef struct linkqueue{ node *front; node *rear;}queue;queue *create(){ queue *q; q=new queue; q->front=NULL; q->rear=NULL; return q;}int length(queue *HQ){ if(HQ==NULL||HQ->rear==NULL) { cout<<"队列的长度为:0"< front; while(p!=NULL) { p=p->next; i++; } cout<<"队列的长度为:"< < front; cout<<"队列中的元素:";// if(p==NULL) { cout<<"空队列"< data<<" ";//打印 p=p->next; } cout< data=num; s->next=NULL; cout< data<<"入队。";// if(HQ->front==NULL)//if(HQ->rear==NULL)//在空队列中进行元素入队操作 { HQ->front=s; HQ->rear=s; } else { HQ->rear->next=s; HQ->rear=s; } cout< front==NULL)//HQ->reat==NULL//在空队列中进行元素出队操作 printf("空队列"); else { x=HQ->front->data; p=HQ->front; cout< front==HQ->rear)//队列中仅仅有一个元素 { HQ->front=NULL; HQ->rear=NULL; } else { HQ->front=HQ->front->next; } free(p); } cout<