Data structure - first understanding of the team

Team

team definition

The linear table that only allows insertion at one end and deletion at the other end is also called a first-in-first-out (First In First Out) linear table, or FIFO for short.
The end that allows insertion is called the tail, and the end that allows deletion is called the head.

The formula for calculating the queue length: length=rear-front+maxsize

team operation

  1. Define data types
#define SIZE  20
typedef int QElemType;
typedef struct
{
    
    
	QElemType data[SIZE];
	int front;
	int rear;
}
  1. team initialization
Status InitQueue(Queue *init_queue)
{
    
    
	init_queue->front = 0;
	init_queue->rear = 0;
	return OK;
}
  1. Team Length Calculation
int QueueLength(Queue *queue)
{
    
    
	return (queue->rear - queue->front + SIZE) % SIZE;
}
  1. Enqueue operation
Status EnQueue(Queue *in_queue, QElemType new_data)
{
    
    
	if((in_queue->rear +1 )%SIZE == in_queue->front){
    
    
		return ERROR;
	}
	in_queue->data[in_queue->rear] = new_data;
	in_queue->rear = (in_queue->rear +1 )%SIZE;
	return ERROR;
}
  1. dequeue operation
Status DeQueue(Queue *out_queue, QElemType *delete_data)
{
    
    
	if(out_queue->rear == out_queue->front)
		return ERROR;
	*delete_data = out_queue->data[out_queue->front];
	out_queue->front = (out_queue->front +1 )%SIZE;
	return ERROR;
}

Guess you like

Origin blog.csdn.net/The_onion/article/details/123598668