Hi guys...
I'm having a problem on my dynamic allocation stack...I try many changes, but unsuccessfully....When the program doesn't freeze, it says "Empty Pile"....
I put here a piece of my work, where I think has a problem....If you need more, I post later.....and If you can't understand, ask me, because I'm too lazy to translate....^^
Fix for me guys
Thanks
you need to provide all involved function.
What does DesceAviao() mean?
What does Desenfileira() do?
the use of Empilha() on line 40 doesn't look right. What happens to the newly created node?
or
I would have expect that on line 14 p and topo are exchanged.
DesceAviao() get a element of queue "v" and put in the stack "d"....
Desenfileira() get a element out of the queue....
I can't undestand what do you talk about the Empilha(), can you explain again?????..."Empilha()" get a element and put in the stack...."Topo" is the stack out of the function....When the Empilha finish, the "p" return in the place of "topo".....
I can't undestand....my objetive is put "p" on the place of "topo", because I get "topo" and the internal values of its for the "p", when I put "aviao" in the top and "topo" below....How can I put the "p" in the place of "topo"????
void Empilha(PILHA *&topo, struct REG &elemento) // Note: *& means you have a reference to your pointer
// i.e. the modification of the pointer will also have an effect on the caller
{
struct NODO *p;
p = (struct NODO * )malloc(sizeof(struct NODO));
p->dado = elemento;
p->proximo = topo;
topo = p; // Note: this will set 'topo' to the newly created node
// no need to return something
return p; // p é o novo topo
}
int DesceAviao(FILA *v, PILHA *&d) // Note: *& is needed here also to transport the change of 'topo' outside of this function!
[EDIT]
By the way: basically, when you pass a (non const) reference like struct REG &elemento to Empilha() means that you can modify elemento and aviao->dado (on line 40) is changed too
[/EDIT]
Thanks coder......I don't believe one "&" would solve my problem...¬¬... C++ is boring and madness....:P
But we need to stand that rock in the shoes....^^