C语言数据结构-4.队列的顺序及链式存储结构

        队列是线性表的一种特殊形式,遵循“先进先出”的原则。队列中一般包含两个指针:一个指针(front)用来指向队首,另一个指针(rear)用来指向队尾。

1.顺序参考代码

1.sequeue.h

#ifndef _SEQ_QUEUE_H_
#define _SEQ_QUEUE_H_

#define FIFO_LEN 10 	/* Max length of the FIFO */
#define N (FIFO_LEN + 1)  /* length of the array = FIFO_LEN + 1 */

typedef int data_t;

/* 
 * cycle queue
 */
typedef struct
{
	data_t	data[N]; 	/* note: the length of the array = FIFO_LEN + 1,
				 * there is an element reserved in the array
				 * which is pointed by the front to mark
				 * out the cycle head of the FIFO 
			 	 * read FullSequeue for more details
			 	 */
	int	front;	/* front always points to the reserved cycle head */

	int	rear;	/* rear point to the rear postion element of the queue */

} sequeue_t;

/* 
 * create a queue and init it as empty 
 * Input:	void
 * Output:	void
 * Return:	new queue, NULL when failed 
 */
sequeue_t *CreateEmptySequeue();

/* 
 * destroy a queue 
 * Input:
 *	queue: the queue to be destroied. 
 * Output:	void
 * Return:	void
 */
void DestroySequeue(sequeue_t *queue);

/* 
 * judge if the queue is empty
 * Input:
 *	queue: the queue to be tested. 
 * Output:	void
 * Return:
 *	1:	empty
 *	0:	not 
 *	-1:	error
 */
int EmptySequeue(sequeue_t *queue);

/* 
 * judge if the queue is full 
 * Input:
 *	queue: the queue to be tested. 
 * Output:	void
 * Return:
 *	1:	full
 *	0:	not 
 *	-1:	error
 */
int FullSequeue(sequeue_t *queue);

/*
 * clear the queue, reset it as empty
 * Input:
 *	queue:	the queue to be cleared. 
 * Output:	void
 * Return:	void
 */
void ClearSequeue(sequeue_t *queue);

/* 
 * In Queue
 * Input:
 *	queue

你可能感兴趣的:(C语言&数据结构,c语言,数据结构)