why the output keep saying the queue is full when i inserting the values???where is the error???

#include<iostream>
using namespace std;
#define size 20

class number
{
private:
int array[size];
int head,tail,count,item;
public:
number();
~number();
void add(int);
void removes();
bool full();
bool empty();
};


number::number()
{
head=0;
tail=-1;
count=0;
}

number::~number() {}

bool number::empty()
{
return bool(count==0);
}

bool number::full()
{
return bool (count=size-1);
}


void number::add(int value)
{
if(!full())
{
tail++;
if (tail==size)
tail=0;
if(count==0)
head=0;
array[tail]=value;
count++;

}
else
cout<<"\t\tQueue is full!!"<<endl;
}

void number::removes()
{
if(!empty())
{
array[head]=item;
head++;
if(head==size)
head=0;
if(count=0)
head=0;
count--;

}
else
cout<<"\t\tQueue is empty!!"<<endl;
}


void main()
{
number value;
int num;


cout<<"Please insert the integers that you want: ";
for(int count=0;count<20;count++)
{
cin>>num;
value.add(num);

}


}





Let consider the function

1
2
3
4
bool number::full()
 {
 return bool (count=size-1);
 }


First of all instead of using the comparision operator you use the assignment operator.
Secondly there is no need to do casting to bool because the expression

count == size

already has bool type.

So the function shall look as

1
2
3
4
bool number::full()
{
   return  ( count == size );
}

Last edited on
Topic archived. No new replies allowed.