//Define the queue element type is void *, so we can change it to all the types
typedefvoid* QElementType;
//Define the queue sturcture
typedefstruct _QueueStruc { int Capacity;//Record the queue size
int Front;//Record the queue front positon
int Rear;//Record the queue rear position
int Size;//Record the queue current data count
QElementType *data;//The queue element data
} QUEUE_STRUC,*QUEUE_STRUC_P;
/*
* FUNCTION NAME: Enqueue
*
* DESCRIPTION:
* Add a element to the queue tail.
*
* parameter:
* Q The Queue will be operated
* data The data will be add to queue tail
* return : none
*/ void Enqueue(QElementType data, QUEUE_STRUC_P Q); /*
* FUNCTION NAME: Dequeue
*
* DESCRIPTION:
* Remove a front element from the current queue.
*
* parameter: Q The Queue will be operate
*
* return : none
*/ void Dequeue(QUEUE_STRUC_P Q); /*
* FUNCTION NAME: FrontAndDequeue
*
* DESCRIPTION:
* Get the front data of the queue, and remove it from the queue
*
* parameter:
* Q The Queue will be operate
*
* return : The front data of the queue
*/
QElementType FrontAndDequeue(QUEUE_STRUC_P Q); /*
* FUNCTION NAME: CreateQueue
*
* DESCRIPTION:
* Create a Queue
*
* parameter:
* QueueSize The Queue size
*
* return :
* The handler of the Queue
*/
QUEUE_STRUC_P CreateQueue(int QueueSize); /*
* FUNCTION NAME: IsQueueEmpty
*
* DESCRIPTION:
* Judge if the queue is empty
*
* parameter:
* Q The Queue will be operated
*
* return :
* 0 The queue is not empty
* 1 The queue is empty
*/ int IsQueueEmpty(QUEUE_STRUC_P Q); /*
* FUNCTION NAME: IsQueueFull
*
* DESCRIPTION:
* Judge if the queue is Full
*
* parameter:
* Q The Queue will be operated
*
* return :
* 0 The queue is not full
* 1 The queue is full
*/ int IsQueueFull(QUEUE_STRUC_P Q); /*
* FUNCTION NAME: DestroyQueue
*
* DESCRIPTION:
* Release the Queue handler, and the memory it malloc
*
* parameter:
* Q The Queue will be operated
*
* return : none
*/ void DestroyQueue(QUEUE_STRUC_P Q); /*
* FUNCTION NAME: MakeQueueEmpty
*
* DESCRIPTION:
* Make a queue empty
*
* parameter:
* Q The Queue will be make empty
* return : none
*/ void MakeQueueEmpty(QUEUE_STRUC_P Q); /*
* FUNCTION NAME: FrontQueue
*
* DESCRIPTION:
* GEt the queue front data
*
* parameter:
* Q The Queue will be operated
*
* return :
* The front data of the queue. if the queue is empty, return -1;
*/
QElementType FrontQueue(QUEUE_STRUC_P Q); #endif// QUEUE_H_INCLUDED
/*
* A Simple Queue Lib implement.
*
* Copyright (C) 2009 Mike Shi
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/ #include<stdio.h> #include<malloc.h> #include"QueueLib.h"