设Q[0,6]是一个静态顺序队列,初始状态为 front=rear-0,请画出做完下列操作后队列的头尾指针的状态变化情况,若不能入对,请指出其元素,并说明理由。 a,b,c,d入队 a,b,c出队 i,j,k,l,m入队 d,i出队 n,o,p,q,r入队
时间: 2023-06-12 09:03:01 浏览: 823
设一循环队列Queue,只有头指针front,不设尾指针,另设一个内含元素个数的计数器,试写出相应的进队、出队算法。
操作前的队列状态:
```
+---+---+---+---+---+---+---+
| | | | | | | |
+---+---+---+---+---+---+---+
front rear
```
a入队后的队列状态:
```
+---+---+---+---+---+---+---+
| a | | | | | | |
+---+---+---+---+---+---+---+
front rear
```
b入队后的队列状态:
```
+---+---+---+---+---+---+---+
| a | b | | | | | |
+---+---+---+---+---+---+---+
front rear
```
c入队后的队列状态:
```
+---+---+---+---+---+---+---+
| a | b | c | | | | |
+---+---+---+---+---+---+---+
front rear
```
d入队后的队列状态:
```
+---+---+---+---+---+---+---+
| a | b | c | d | | | |
+---+---+---+---+---+---+---+
front rear
```
a,b,c出队后的队列状态:
```
+---+---+---+---+---+---+---+
| | | | d | | | |
+---+---+---+---+---+---+---+
front rear
```
i入队后的队列状态:
```
+---+---+---+---+---+---+---+
| | | | d | i | | |
+---+---+---+---+---+---+---+
front rear
```
j入队后的队列状态:
```
+---+---+---+---+---+---+---+
| | | | d | i | j | |
+---+---+---+---+---+---+---+
front rear
```
k入队后的队列状态:
```
+---+---+---+---+---+---+---+
| | | | d | i | j | k |
+---+---+---+---+---+---+---+
front rear
```
l入队后的队列状态:
```
+---+---+---+---+---+---+---+
| | | | d | i | j | k |
+---+---+---+---+---+---+---+
front rear
```
m入队后的队列状态:
```
+---+---+---+---+---+---+---+
| | | | d | i | j | k |
+---+---+---+---+---+---+---+
front rear
```
d,i出队后的队列状态:
```
+---+---+---+---+---+---+---+
| | | | | | j | k |
+---+---+---+---+---+---+---+
front rear
```
n入队后的队列状态:
```
+---+---+---+---+---+---+---+
| n | | | | | j | k |
+---+---+---+---+---+---+---+
front rear
```
o入队后的队列状态:
```
+---+---+---+---+---+---+---+
| n | o | | | | j | k |
+---+---+---+---+---+---+---+
front rear
```
p入队后的队列状态:
```
+---+---+---+---+---+---+---+
| n | o | p | | | j | k |
+---+---+---+---+---+---+---+
front rear
```
q入队后的队列状态:
```
+---+---+---+---+---+---+---+
| n | o | p | q | | j | k |
+---+---+---+---+---+---+---+
front rear
```
r入队后的队列状态:
```
+---+---+---+---+---+---+---+
| n | o | p | q | r | j | k |
+---+---+---+---+---+---+---+
front rear
```
因为队列已经满了,无法再入队任何元素。
阅读全文