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

📄 queue.h

📁 Adhoc无线网络路由协议源码
💻 H
字号:
#ifndef QUEUE_H
#define QUEUE_H

#include <stdio.h>
#include <stdlib.h>

struct packet {
	unsigned char *buf;
	unsigned int len;
};

#define QDATUM struct packet *

/*
 *  Queue item structure
 */
struct qentry
{
	struct qentry *next;
	QDATUM d;
};

/*
 *  Queue container structure
 *
 *  This structure encapsulates a linked list of qentry items.
 */
struct queue
{
	struct qentry *begin, **end;
};


/*
 *  qinit: Initialize queue.
 *
 *  Parameters:
 *
 *    q		Pointer to a queue, or NULL if the user wishes to leave 
 *		it to qinit to allocate the queue.
 *
 *  Return values:
 *
 *    non-NULL  Queue has been initialized.
 *
 *    NULL	Insufficient memory.
 */
struct queue *
qinit(struct queue *q);

/*
 *  qunsert: append an item to the queue.
 *
 *  Parameters:
 *
 *    q		Pointer to a queue. It is assumed the queue has been
 *		initialized by a call to qinit.
 *
 *    d		Item to be appended.
 *
 *  Return values:	
 *
 *    1 	The item has been appended.
 *
 *    0		The item could not be appended. Either the queue 
 *              pointer provided was NULL, or the function was unable 
 *              to allocate the amount of memory needed for a new 
 *              queue item. 	
 */
int
qinsert(struct queue *q, QDATUM d);


/*
 *  qremove: remove an item from the queue.
 *
 *  Parameters:
 *
 *    q		Pointer to a queue.
 *
 *    d		Pointer to the QDATUM variable that will hold the datum
 *		corresponding to the queue item.
 *
 *  Return values:
 *
 *    non-NULL	An item has been removed. The variable that d points 
 *              to now contains the datum associated with the item 
 *              in question.
 *		
 *    NULL	No item could be removed. Either the queue pointer 
 *              provided was NULL, or the queue was empty. The memory 
 *              location that d points to has not been modified. 
 */
QDATUM *
qremove(struct queue *q, QDATUM *d);

/*
 *  qpeek: access an item without removing it from the queue.
 *
 *  Parameters:
 *
 *    q		Pointer to a queue.
 *
 *    d		Pointer to the QDATUM variable that will hold the datum
 *		associated with the first item in the queue, i. e.,
 *		the item that would be removed had qremove been called
 *		instead of qpeek.
 *
 *  Return values:
 * 
 *    See qremove.
 */
QDATUM *
qpeek(struct queue *q, QDATUM *d);

#endif

⌨️ 快捷键说明

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