minkee 2020-06-09
数据结构::线性队列
#include <iostream> using namespace std; #define MaxSize 10 /*//链栈 typedef struct Linknode{ int data; struct Linknode *next; }*LiStack; */ //队列 typedef struct { int data[MaxSize]; int front; int rear; }SqQueue; void InitQueue(SqQueue &Q) { Q.front =0; Q.rear=0; } bool QueueEmpty(SqQueue Q) { if(Q.front == Q.rear) return true; else return false; } bool EnQueue(SqQueue &Q,int 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,int &x) { if(Q.front==Q.rear) return false; x=Q.data[Q.front]; Q.front=(Q.front+1)%MaxSize; return true; } bool GetHead(SqQueue &Q,int &x) { if(Q.front==Q.rear) return false; x=Q.data[Q.front]; return true; } int main() { SqQueue Q; return 0; }