1.循环队列入队列和出队列代码

int in(queue *list, datatype *element)
{
	//判断list是否创建, 是否满
	if(NULL==list || list->front == (list->rear+1) % MAXSIZE)
	{
		puts("error or full");
		return -1;
	}

	strcpy(list->data[list->rear], element); //元素数据类型位字符串数组,不能直接赋值
	//printf("\t in--> list-data[%d]=%s\n", list->rear ,list->data[list->rear]);
	
	list->rear = (list->rear + 1) % MAXSIZE; //队尾指针加1
	//printf("list->rear=%d\n", list->rear);
	//printf("list->front=%d\n", list->front);

	return 0;
}

int out(queue *list)
{
	//判断是否创建,是否为空
	if(NULL==list||list->rear==list->front)
	{
		puts("error or empty");
		return -1;
	}
	
	printf("delete queue element is %s\n", list->data[list->front]);
	list->front = (list->front + 1) % MAXSIZE;
	return 0;

	
}

目录:学习笔记快速链接

12-03 08:19