标签:数据 c语言 queue temp efi 清空 sizeof 出队 结构
#include <stdio.h> #include <tchar.h> #include <stdlib.h> #define MaxQueueSize 100 // TODO: 在此处引用程序需要的其他头文件 struct Node{ int data; Node* next; }; struct Queue{ Node* front; Node* rear; }; //初始化队列 bool Init_Queue(Queue* q){ q->front = q->rear = (Node*)malloc(MaxQueueSize*sizeof(Node)); if (!q->front) return false; q->front->next = NULL; return true; } //清空队列 bool Clear_Queue(Queue* q){ q->front = q->rear; return true; } //销毁队列 bool Destroy_Queue(Queue* q){ Node* temp = q->front; while (q->front != q->rear){ temp = q->front->next; free(q->front); q->front = temp; } q->front = q->rear = NULL; return true; } //入队 bool EnQueue(Queue* q, int value){ Node* n = (Node*)malloc(sizeof(Node)); n->next = NULL; n->data = value; q->rear->next = n; q->rear = n; return true; } //出队,返回队头元素的值 int DeQueue(Queue* q){ int temp; if (q->front == q->rear) exit(-1); Node* p = q->front; temp = p->next->data; q->front = p->next; if (p == q->rear) q->front = q->rear; free(p); p = NULL; return temp; } //打印队列 void Print_Queue(Queue q){ if (q.front == q.rear) printf("空队列\n"); while (q.front != q.rear){ printf("%d\n", DeQueue(&q)); } }
标签:数据 c语言 queue temp efi 清空 sizeof 出队 结构
原文地址:http://www.cnblogs.com/xin1998/p/7745912.html