c语言代码求循环队列长度
时间: 2024-05-30 10:14:22 浏览: 97
C语言实现循环队列代码
Sure, I can help you with that. Here's an example of C language code to find the length of a circular queue:
int front, rear, count;
int cq[5];
void cq_length() {
if(front == -1 && rear == -1) {
printf("\nCircular Queue is Empty.");
}
else {
count = (rear+5-front) % 5 + 1; //calculating length of circular queue
printf("\nLength of Circular Queue: %d", count);
}
}
In this code, we are initializing front, rear, and count as integers and cq as an array. Then, we define a function cq_length() to find the length of the circular queue. Finally, we calculate the length using a formula and print the output.
Hope this helps! Let me know if you have any more questions.
阅读全文