how to find number of elements in a Circular Queue

后端 未结 13 1449
我寻月下人不归
我寻月下人不归 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 04:03
     Pointer1 = head; // (your node)
     count = 0;
    
    
     if( Pointer1 != NULL )
     {
       count = 1;
       Pointer2 = Pointer1->Next;
       while ( Pointer2 != NULL && Pointer2 != Pointer1 )
       {
         count++;
         Pointer2 = Pointer2->Next;
       }
     }
    
     return count;
    
    0 讨论(0)
提交回复
热议问题