how to find number of elements in a Circular Queue

后端 未结 13 1567
我寻月下人不归
我寻月下人不归 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:40

    int lenghtQueue(queue* q){
    
         int len =0 ;
         if (isEmpty(q))
                return 0 ;
    
          queue* qe = q->next ;
          len ++ ;
    
           while(qe!=q){
                 len ++ ;
                 qe=qe->next ;           
           }
               return len ;
      }
    

提交回复
热议问题