更新
This commit is contained in:
		
							
								
								
									
										62
									
								
								数据结构/队列/queue.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								数据结构/队列/queue.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,62 @@ | ||||
| /* | ||||
| *@文件:queue.h | ||||
| *@作者:‘你遇了我’ | ||||
| *@time:2022/11/13 | ||||
| *@联系:QQ:321640253 | ||||
| *@版本:V1.2 | ||||
| *@描述:数组泛型队列,队列管理和容器空间分离 | ||||
| 使用案例 | ||||
|     int a[10];                      //创建队列容器 | ||||
|     SqQuecu a_quecu;                //初始化队列 | ||||
|     InitQuecu(&a_quecu,10,sizeof(int),(void*)a); | ||||
|  | ||||
|     //出队进队测试 | ||||
|     int *tmep;//临时存储进对的返回值 | ||||
|     for (size_t i = 0; i < 50; i++) | ||||
|     { | ||||
|         tmep = (int*)enQueue(&a_quecu); | ||||
|         if(tmep!=NULL){                         //返回值为空指针则对满 | ||||
|             *tmep=i; | ||||
|         } | ||||
|         else{ | ||||
|             printf("出队元素:%d\n",*(int*)deQueue(&a_quecu)); | ||||
|             *(int*)enQueue(&a_quecu)=i;                             //出队后重新进队 | ||||
|         } | ||||
|         for(int i=0;i<10;i++) | ||||
|         printf("%d\n",a[i]); | ||||
|  | ||||
|         printf("-------------------------\n"); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     //连续退队测试 | ||||
|     for(int i=0;i<5;i++){ | ||||
|         printf("出队元素:%d\n",*(int*)deQueue(&a_quecu)); | ||||
|         printf("当前队列长度:%d\n",a_quecu.size); | ||||
|     } | ||||
| */ | ||||
|  | ||||
| #ifndef LIST_QUEUE_H | ||||
| #define LIST_QUEUE_H | ||||
|  | ||||
| #include "stdint.h" | ||||
| #include "stdbool.h" | ||||
| #include "stdlib.h" | ||||
|  | ||||
|  | ||||
| typedef struct{ | ||||
|     uint16_t Maxsize;           //数组最大长度 | ||||
|     uint16_t NodeSize;          //数组元素的空间大小 | ||||
|     void *container;            //容器的指针 | ||||
|     int front,rear;             //尾和头 | ||||
|     uint16_t size;              //队列长度 | ||||
| } SqQuecu; | ||||
|  | ||||
| void InitQuecu(SqQuecu *Q,uint16_t Maxsize,uint16_t NodeSize,void *container); | ||||
| void *enQueue(SqQuecu *Q); | ||||
| void *deQueue(SqQuecu *Q); | ||||
| bool QueueEmpty(SqQuecu *Q); | ||||
| bool QueueFull(SqQuecu *Q); | ||||
|  | ||||
|  | ||||
| #endif //LIST_QUEUE_H | ||||
		Reference in New Issue
	
	Block a user