队列学习一
作者:互联网
#include <iostream> #include<cstdio> using namespace std; typedef struct LinkNode {//队列链式结构 int Data; struct LinkNode* next; }LinkNode; typedef struct { LinkNode* front; LinkNode* rear; }LinkQueue; typedef struct Link {//队列线性结构 int Data[100]; int front; int rear; }Link; bool InitQueue(LinkQueue& Q)//队列初始化 { Q.front = Q.rear = new LinkNode; if (Q.front == NULL) return false; Q.front->next = NULL; return true; } bool EnQueue(LinkQueue& Q, int& data)//入队操作 { LinkNode* s = new LinkNode; if (s == NULL) return false; s->Data = data; s->next = NULL; Q.rear->next = s; Q.rear = s; return true; } bool DeQueue(LinkQueue& Q, int& data)//出队操作; { if (Q.front == Q.rear) return false; LinkNode* p = Q.front->next; data = p->Data; Q.front->next = p->next; if (Q.rear == p) Q.rear = Q.front; delete[] p; return true; } bool EmptyQueue(LinkQueue Q) { if (Q.front == Q.rear) return true; return false; } int main() { LinkQueue Q; InitQueue(Q); int data; cin >> data; while (data != 000) { EnQueue(Q, data); cin >> data; } while (!EmptyQueue(Q)) { DeQueue(Q, data); cout << data << endl; } return true; }
标签:return,队列,data,学习,int,front,LinkNode,rear 来源: https://www.cnblogs.com/Mexcellent/p/15081152.html