dont konw what to do next.

Im doing the tower of hanoi but without recursion.

Im trying to do it with linked list.

I have managed to write the algoritm but I dont know how to make it repeat it self until it finds the solution.

if I check the debugger Im getting the first step correctly but then It needs to use the head again and use the same algoritm on it and so on untill it finds the first solution.

Code:

#include <stdio.h>

#include <stdlib.h>

typedef struct hanoi{

int nod ; // number of disks //

int spole ; // source pole number //

int dpole; // destination pole number //

struct hanoi *next;

} hanoi;

hanoi *insert(hanoi *head );

void main()

{

hanoi *head ;

head =(hanoi *) malloc (sizeof (hanoi)) ;

head->next=NULL;

printf("please, enter the number of disks\n") ;

scanf("%d", &head->nod);

printf("the source pole number\n") ;

scanf("%d", &head->spole);

printf("the destination pole number\n");

scanf("%d", &head->dpole);

insert(head);

}

hanoi *insert(hanoi *head )

{

hanoi *temp;

temp =(hanoi *) malloc (sizeof ( hanoi)) ;

temp->next =( hanoi *) malloc (sizeof ( hanoi)) ;

temp->next->next = (hanoi *) malloc (sizeof ( hanoi)) ;

// nod //

temp->nod = head->nod -1 ;

temp->next->next->nod = head->nod -1 ;

temp->next->nod = 1 ;

// spole //

temp->spole = head->spole ;

temp->next->spole = head->spole ;

temp->next->next->spole=6-head->spole-head->dpole;

// dpole //

temp->next->dpole = head->dpole ;

temp->next->next->dpole = head->dpole ;

temp->dpole = head->spole=6-head->spole-head->dpole;

temp->next->next->next=NULL;

return temp;

}

I didnt understand anything

so what do I have to do next?