首页 > 试题广场 >

以下哪一条操作序列可以使 pFront 变为 1 , pBa

[单选题]

现在有一个长度为 5 的环形队列为 quene ,使用数组实现,队首元素所在下标 pFront 值为 3 ;新数据要插入的位置下标 pBack 值为 2


以下哪一条操作序列可以使 pFront 变为 1 pBack 的值变为 0 ()

  • pop;push;pop;pop;push;pop;push;
  • push;pop;push;pop;pop;push;pop
  • push;push;;push;push;pop;push;push;
  • push;push;pop;pop;push;pop;pop
珹头像
题目出错
没有答案
应该有3个pop,4个push
发表于 2019-11-01 09:38:19 回复(0)
不考虑扩容,3次pop,pFront下标依次为3->4->0->1,3次push,pBack下标依次为2->3->4->0;如果扩容因子是2的话,下一次push触发扩容,数组容量变为10,pFron下标初始化为0,pBack下标初始化为4。再经过push6次pop1次后正好满足pBack下标为0,pFront下标为1,那么应该选C
编辑于 2019-11-14 21:21:55 回复(0)
不懂问题,疑问:是否可以覆盖元素?新数据要插入的位置下标 pBack 值为 2 ,是否表示只能在2位置插入?
发表于 2019-11-17 06:11:14 回复(0)
选A,个人感觉
发表于 2019-11-01 07:54:17 回复(0)

答案选未知

【解析】


  • A:pop;push;pop;pop;push;pop;push
type start pop push pop pop push pop push
PFront 3 4 4 0 1 1 2 2
PBack 2 2 3 3 3 4 4 0
  • B:pop;push;pop;pop;push;pop;push
type start pop push pop pop push pop push
PFront 3 4 4 0 1 1 2 2
PBack 2 2 3 3 3 4 4 0
  • C:push;push;;push;push;pop;push;push;
type start push push push push pop push push
PFront 3 3 3 3 3 4 4 4
PBack 2 3 4 0 1 1 2 3
  • D: push;push;pop;pop;push;pop;pop
type start push push pop pop push pop pop
PFront 3 3 3 4 0 0 1 2
PBack 2 3 4 4 4 0 0 0
发表于 2019-10-31 14:00:15 回复(0)