⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queue.c

📁 接收端的程序
💻 C
字号:
#include 	<stdio.h>#include 	<string.h>#include 	<stdlib.h>#include	"logging.h"	#include 	"queue.h"/**************************************************************************************************				函数功能: 初始化队列,为队头和队尾指针分配空间***************************************************************************************************/void InitQueue(LinkQueue *Q){	Q->front=Q->rear=(Queueptr)malloc(sizeof(QNode));	if(!Q->front) 	{		log_fatal("QUEUE","Initial the queue failure!\n");		exit(1);	}	Q->front->next=NULL;		log_info("QUEUE","The Queue has been initialized!");}void DestroyQueue(LinkQueue *Q){	while(Q->front)	{		Q->rear=Q->front->next;		free(Q->front);		Q->front=NULL;		Q->front=Q->rear;	}		log_debug("QUEUE","The Queue has been destroyed!");}/********************************************************************************************			函数功能: 入队			@ e: 要存入队列的值*********************************************************************************************/void Enqueue(LinkQueue *Q,struct eventinfo e){	Queueptr p=(Queueptr)malloc(sizeof(QNode));	if(!p)	{			log_error("QUEUE","Can not malloc for enqueue!");		exit(1);	}	p->data=e;	strcpy(p->data.time_stamp,e.time_stamp);	strcpy(p->data.ip,e.ip);	strcpy(p->data.serverity,e.serverity);	strcpy(p->data.facility,e.facility);	strcpy(p->data.source,e.source);	strcpy(p->data.content,e.content);	p->next=NULL;	Q->rear->next=p;	Q->rear=p;	}			/********************************************************************************************			函数功能: 出队			@ e: 将弹出队列的元素保存在e中******************************************************************************************/void Dequeue(LinkQueue *Q,struct eventinfo *e){	Queueptr p;	if(Q->front==Q->rear) exit(1);	p=Q->front->next;	strcpy(e->time_stamp,p->data.time_stamp);	strcpy(e->ip,p->data.ip);	strcpy(e->source,p->data.source);	strcpy(e->facility,p->data.facility);	strcpy(e->serverity,p->data.serverity);	strcpy(e->content,p->data.content);	Q->front->next=p->next;	if(Q->rear==p) Q->rear=Q->front;	free(p);	p=NULL;			}			/************************************************************************************************				函数功能: 打印队列				(主要用来调试)**************************************************************************************************/void PrintQueue(LinkQueue *Q){	Queueptr p;	p=Q->front->next;	while(p!=Q->rear)	{		printf("%s\n",p->data.ip);		printf("%s\n",p->data.facility);		printf("%s\n",p->data.serverity);		printf("%s\n",p->data.source);		printf("%s\n",p->data.content);	}	printf("%s\n",p->data.ip);	printf("%s\n",p->data.facility);	printf("%s\n",p->data.serverity);	printf("%s\n",p->data.source);	printf("%s\n",p->data.content);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -