Dear all,
I am implementing a circular queue, but I can't find the formula to obtain the size of the queue; this one doesn't work correctly and gives me wrong results:
int size = abs (m_tail - m_front) ;
where m_front and m_tail are the indexes of the queue's front and tail respectively.
#include <iostream>
usingnamespace std;
int main()
{
int absolute;
int first,last;
cout<<"Enter a big number: ";
cin>>first;
cout<<"Enter another one(smaller): ";
cin>>last;
absolute=abs(first-last);
cout<<"Absolute: "<<absolute;
cin.ignore();
cin.get();
}
Thank you for the code snippet but it doesn't seem to be the same case since what you are implementing is not a circular queue. By definition, in a circular queue, the front and tail indexes are set to zero when they reach the max_size , which is expressed here by a modulo. May be I don't explain my problem correctly but your code does simply calculate the difference between two numbers and shows the result, doesn' it??