本文包含了三个文件
1. loopqueue.c //环形链表的C语言
2. loopqueue.h //环形链表的头文件
3. main.c //测试代码
loopqueue.c
#include "stdlib.h"
#include "loopQueue.h"
#include "stdio.h"
typedef struct{
char *buf;
char head;
char tail;
uint32 size;
uint32 capacity;
}LoopQueue_Handle_T;
PUBLIC LP_HANDLE loopQueue_create(uint32 len){
LoopQueue_Handle_T* handle = (LoopQueue_Handle_T*)malloc(sizeof(LoopQueue_Handle_T));
if(!handle){
printf("loopQueue out of memory\n");
return SCI_FALSE;
}
handle->buf = (char*)malloc(len);
if(!handle->buf){
printf("loopQueue out of memory\n");
return SCI_FALSE;
}
handle->tail=0;
handle->head=0;
handle->size=0;
handle->capacity = len;
return (LP_HANDLE)handle;
}
PUBLIC void loopQueue_delete(LP_HANDLE handle){
LoopQueue_Handle_T *lp_ptr = (LoopQueue_Handle_T *)handle;
if(!lp_ptr)
return;
free(lp_ptr->buf);
free(lp_ptr);
}
//½«len³¤µÄbuf¼ÓÈëµ½lpÖÐ
PUBLIC int loopQueue_push(const LP_HANDLE handle,char *buf,uint32 len){
uint32 i;
LoopQueue_Handle_T *lp_ptr = (LoopQueue_Handle_T *)handle;
if((lp_ptr->size+len)>lp_ptr->capacity){
printf("loopQueue overflow\n");
return SCI_FALSE;
}