Good morning, I try to build a 'game' version of Towers of Hanoi that later can either be solved manually or by the algorithm itself. The user can choose the amount of disks on the pole. Now I try to design the disks on the pole as linked list since I wanted to use those to learn understand them. The following code is of course only temporary, partly and incomplete but I would be delighted if you could help me find the bug/ tell me if I miss on something. This only handels the creation of all disks at the begin for now.
typedef struct disk{ int placeholder; struct disk *left; struct disk *right; } disk;
void pileUp(disk *pole)
{
int disks = 0;
disk *next = pole->right;
pole->left = NULL;
// input
printf("D: ");
scanf("%d", &disks);
//end
while(disks > 0)
{
next = malloc(sizeof(*pole)); //alloc another diskspace
next->placeholder = disks; //placeholder value
printf("%d\t%p\n", next->placeholder, &next); //check on each
next = next->right; //iterate
--disks;
}
}
int main(int argc, char *argv[])
{
disk pole1, pole2, pole3;
pileUp(&pole1);
return 0;
}