how to find number of elements in a Circular Queue

后端 未结 13 1576
我寻月下人不归
我寻月下人不归 2021-01-13 03:10

how do i find the number of items in a circular queue?

|front - rear| doesnt always work.

is there one equation to know how many element is in a cir

13条回答
  •  情歌与酒
    2021-01-13 03:51

    No of items in Circular queue is,

    size = (N-f+r) mod N
    

    where

    • N is the size of array used in circular fashion
    • f index of the front element
    • r index immediately past the rear element

    This formula work for both liner and circular queues.

提交回复
热议问题