标签:out lin cout def let i++ clu false queue
#include<iostream> using namespace std; #define ElemType int const int MaxSize=50; typedef struct{ ElemType data[MaxSize]; int front=0,rear=0; }SqQueue; bool EnQueue(SqQueue &Q,ElemType x){ if((Q.rear+1)%MaxSize==Q.front)return false; Q.data[Q.rear]=x; Q.rear=(Q.rear+1)%MaxSize; return true; } bool DeQueue(SqQueue &Q,ElemType &x){ if(Q.front==Q.rear)return false; x=Q.data[Q.front]; Q.front=(Q.front+1)%MaxSize; return true; } int Length(const SqQueue &Q){ return (Q.rear-Q.front+MaxSize)%MaxSize; } int main(){ SqQueue Q; for(int i=1;i<=10;i++){ EnQueue(Q,i); } cout<<Length(Q)<<endl; int x; while(Q.front!=Q.rear){ DeQueue(Q,x); cout<<x<<" "; } cout<<endl; return 0; }
#include<iostream> using namespace std; #define ElemType int typedef struct QNode{ ElemType data; struct QNode *next; }QNode; typedef struct{ QNode *front,*rear; }LinkQueue; void EnQueue(LinkQueue &Q,ElemType x){ QNode *p=new QNode; p->data=x; p->next=NULL; Q.rear->next=p; Q.rear=p; } bool DeQueue(LinkQueue &Q,ElemType &x){ if(Q.front==Q.rear)return false; QNode *p=Q.front->next; x=p->data; Q.front->next=p->next; if(p==Q.rear)Q.rear=Q.front; delete p; return true; } int main(){ LinkQueue Q; Q.front=Q.rear=new QNode; Q.front->next=NULL; for(int i=1;i<=10;i++){ EnQueue(Q,i); } int x; while(Q.front!=Q.rear){ DeQueue(Q,x); cout<<x<<" "; } cout<<endl; return 0; }
标签:out lin cout def let i++ clu false queue
原文地址:https://www.cnblogs.com/lyt888/p/12562562.html