template <class T>
class Queue {
private:
array<T,10> elems;
int frt=-1,bck=-1;
};
When i run the following code of snippet
template<class T>
void Queue<T>::Enque(T const& item){
cout<<"Size of array:"<<elems.size()<<"\n";
if(bck<elems.size())
{
if(bck==-1)frt=0;
++bck;
elems.at(bck)=item;
cout<<"Element Inserted\n";
}
else
cout<<"Queue is overflow\n";
}
I get this output
Here it is showing that the size
is 10 and the value of bck
is -1 but it is going to the else statement.
But if I replace the if condition
with if(bck<10)
the code is working fine.
Can anyone help me in identifying this behavior.
Aucun commentaire:
Enregistrer un commentaire