Tad struct pilha

Hello all personal jewelry?

I'm having problem with code I'm trying to develop, it is a game Tower of Hanoi, is a college project, the code is in the process I used ADT for a struct cells, formed by the functions; stack, unstack, InicializarPilhas, SelectPUsh, SelectPop, ExibirPilhas, Menu, the code is running the following hap, three pile pi1 value on the stack, there pops the top value of the normal up there, but I need to pile on another stack pops this value, then I I did when I ask to unstack I say keep the value in AUX2,
So for everyone who is unstacked in all cells, now I need to stack this value this AUX2 in pi2, for this I call case3 using the function SelectPush (& p, a, AUX2), when I use this function the value of AUX2 pi2 and piled in, but the case and that was for the pi1 stack is empty because the value was removed from her to go to pi2, and value in contunua pi1, so for all the cells that are then stacked and unstacked, I accretive that the difficulty level is in case3 but do not know how to solve, if someone could help me I thank


Below is the code problems with:


#include <stdio.h>
# Include
# Define MAX 3

/ / Structure of the stack / /
typedef struct stack {
vet int [MAX];
int top;
Stack};

/ / Create stack / /
Stack pi1, pi2, PI3;

/ / Prototyping functions / /
void push (Stack * p, int i);
int pop (Stack * p);
void InicializarPilhas (Stack * p);
void SelectPush (Stack * p, int a, int AUX2);
int SelectPop (Stack * p, int num);
void ExibirPilhas (Stack * p);
void Menu (void);

/ * For the value functions enchegar unstacked to carry is a cell
to another * /
int AUX2;

int main () {
struct Stack p;
int num, adc;
char op;
InicializarPilhas (& p);
Menu ();

do {
scanf ("% c", & op);
switch (op) {

case '1 ':
{
printf ("Enter the value to stack \ n");
scanf ("% d", & adc);
Stack (& ​​pi1, adc);
ExibirPilhas (& pi1);
scanf ("% c", & op);
break;
}
case '2 ':
{
printf ("\ unstacking component in the direction");
scanf ("% d", & num);
SelectPop (& p, num);
printf ("\ nvalue unstacked% d", AUX2);
scanf ("% c", & op);
break;
}

case '3 ':
{
printf ("Enter the direction to stack");
scanf ("% d", & num);
SelectPush (& p, a, AUX2);
scanf ("% c", & op);
break;
}
}
}
while (op! = 3);
system ("pause");
}

/ / Function to stack the data generically / /
void push (Stack * p, int i) {
if (p-> top == MAX) {
printf ("\ nthe stack is full");
return;
}
p-> v [p-> top] = i;
p-> top + +;
}

/ / Function to unstack the data generically / /
int pop (Stack * p) {
p-> top -;
if (p-> top == 0) {
printf ("\ nthe stack is empty");
}
p-> v [p-> top];
return p-> v [p-> top];
}

/ / Function to initialize the tops of the stack with value 0 / /
void InicializarPilhas (Stack * p) {
pi1.topo = 0;
pi2.topo = 0;
pi3.topo = 0;
}

/ / Function to select the directions from the Which data will be stacked / /
void SelectPush (Stack * p, int a, int AUX2) {
if (a == 1) {
Stack (& ​​pi2, AUX2);
ExibirPilhas (& pi2);
Else {}
if (a == 2) {
Stack (& ​​PI3, AUX2);
ExibirPilhas (PI3 &);
Else {}
if (a == 3) {
Stack (& ​​pi1, AUX2);
ExibirPilhas (& pi1);
}
}
}
}

/ / Function to select the directions from the Which data will be unstacked / /
int SelectPop (Stack * p, int num) {
if (a == 1) {
AUX2 = pop (& pi1);
ExibirPilhas (& pi1);
Else {}
if (a == 2) {
AUX2 = pop (& pi2);
ExibirPilhas (& pi2);
Else {}
if (a == 3) {
AUX2 = pop (& PI3);
ExibirPilhas (PI3 &);
}
}
}
}


/ / Function to print the date of cells / /
void ExibirPilhas (Stack * p) {
int i;
for (i = p-> top-1; i> = 0; i -) {
pi1.vet [i];
}
for (i = p-> top-1; i> = 0; i -) {
pi2.vet [i];
}
for (i = p-> top-1; i> = 0; i -) {
pi3.vet [i];
printf ("\ n% d \ t% d \ t% d", pi1.vet [i], pi2.vet [i], pi3.vet [i]);
}
printf ("\ n (A) \ t (B) \ t (C)");
}

/ / Function to display the menu of hits / /
void Menu (void) {
printf ("\ nMenu");
printf ("\ n1-Stack");
printf ("\ n2-Unstack");
printf ("\ n3-Insert");
}
Last edited on
english?
No chipp, that's portuguese. hehe. :-P

I know, I'm a funny guy! :-D
maybe the others could help as i didn't understand hanoi algorithm... :D
@webjose: i mean: "could you give us in english?" :)) and yeah, this is the first time i saw foreign language (beyond english) written in here, i thought it was a spam... :))
Topic archived. No new replies allowed.