front指向队头元素的前一个元素,raer指向队尾元素
(写题时,只是单说循环单链表的,默认就是这种)
判断空满
队空 :
front = rear;
入队:
rear = (rear+1)%MaxSize; queue rear = x;
堆满时:
front == (rear + 1 )%MaxSize;
判断元素个数
在rear >front 时
个数为 : rear - front
在rear < front 时
个数为:rear + 1 + MaxSize - front - 1 = rear - front + MaxSize
元素个数归纳为
个数为:(rear - front + MaxSize)%MaxSize
front指向队头元素,raer指向队尾元素的后一个元素
判断空满
队空 :
front = rear;
入队:
rear = (rear+1)%MaxSize; queue rear = x;
堆满时:
留出一个位置区分堆满和队空状态
front == (rear + 1 )%MaxSize;
判断元素个数
同上
元素个数归纳为
个数为:(rear - front + MaxSize)%MaxSize
front指向队头元素,raer指向队尾元素
判断空满
队空 :
front =(rear+1)%MaxSize;
入队:
rear = (rear+1)%MaxSize; queue rear = x;
堆满时:
留出一个位置区分堆满和队空状态
front == (rear + 2 )%MaxSize;
判断元素个数
在rear >front 时
个数为 : rear - front +1
在rear < front 时
个数为:rear + 1 + MaxSize - front
元素个数归纳为
个数为:(rear - front +1 + MaxSize)%MaxSize
标签:队空,队列,元素,个数,MaxSize,队满,front,rear From: https://www.cnblogs.com/kuailest/p/16831586.html