Hi, I'm doing a program to insert and remove a circular queue of integers of size 5 and printing on the screen the list with the elements who are in it.
When I run the program it runs normal, but after a insertions and deletions gives it fails to run.
I can not find where is the problem. Could anyone help me?
You can't expect someone to sign up for some service just to help you with your code. The strange message I posted earlier is what I get when I attempted to download your code.
If you would like someone here to help you, you'll need to post your code here. Also, if you post your code here, the thread can serve as help for someone else in the future.
Also, remember to use the code format tag around your code so your formatting is preserved and so we can read it.
Sorry kbw, I do not placed the code here because the code are subdivided in class and it is very large to place here. But I agree with you about the link.
So, follows all the code:
Let's take a look at entra(). The code is correct, but it's more complicated than it needs to be:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
void Fila::entra(int elem, bool &deuCerto) {
if (this->cheia())
deuCerto = false;
else {
if (this->total < MAX) {//fim no ultimo elemento e inicio não no inicio
this->elemento[this->fim] = elem;
this->total++;
if (this->fim == MAX - 1)
this->fim = 0;
elsethis->fim++;
deuCerto = true;
} else {
deuCerto = false;
}
}
}
First, you don't need to keep using this-> to reference class variables. It's necessary in other languages, but just using total implies this->total.
if (this->total < MAX) This code is unnecessary as you know that the queue has space for another element because you're already tested it with if (this->cheia()).
In method sai(), you use the construct this->inicio = this->inicio++; This is really bad, if you want to increment a value, ++inicio is the correct method.