本文包含了三个文件
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;
}

本文提供了一组C语言代码实现环形队列,包括`loopqueue.c`的环形链表实现,`loopqueue.h`的头文件定义,以及`main.c`的测试用例,展示了环形队列的基本操作。
最低0.47元/天 解锁文章
441

被折叠的 条评论
为什么被折叠?



