コード例 #1
0
ファイル: toh.c プロジェクト: SanketDG/algorithms-ds-c
void toh(int n, char source, char dest, char temp)
{
    if(n > 0)
    {
        toh(n-1, source, temp, dest);
        printf("Move disk %d from %c to %c\n", n, source, dest);
        toh(n-1, temp, dest, source);
    }
}
コード例 #2
0
ファイル: tow_of_hanoi.c プロジェクト: sagar55/MyProg
void toh(int n,char S,char T,char D)
      {
           if(n==1)
               printf("move disk 1 from %c to %c\n",S,D);
           else
           {
               toh(n-1,'S','D','T');
               printf("move disk %d from %c to %c\n",n,S,D);
               toh(n-1,'T','S','D');
           }
      }    
コード例 #3
0
ファイル: 3299.c プロジェクト: aaronz/algo
int main()
{
    double h, t, d;
    double x, y;
    char a, b;
    while (scanf("%c %lf %c %lf\r\n", &a, &x, &b, &y) && a != 'E')
    {
        h = t = d = MAX;

        if (a == 'T')
            t = x;
        else if (a == 'D')
            d = x;
        else
            h = x;

        if (b == 'T')
            t = y;
        else if (b == 'D')
            d = y;
        else
            h = y;

        if (h == MAX)
            h = toh(t, d);
        else if (t == MAX)
            t = tot(d, h);
        else
            d = tod(t, h);
        printf("T %.1f D %.1f H %.1f\r\n", t, d, h);
    }
}
コード例 #4
0
ファイル: toh.c プロジェクト: SanketDG/algorithms-ds-c
int main(void)
{
    int n;
    char source = 'A', dest = 'C', temp = 'B';
    printf("Enter the no of disks: \n");
    scanf("%d", &n);
    toh(n, source, dest, temp);
}
コード例 #5
0
ファイル: tower_of_hannoi.c プロジェクト: shivendr/Ccodes
       void toh(Node *a,Node *b, Node *c, int n)
       {
            if(n==1)
            {
            int p=pop(a);
            push(b,p);
            }
            else
            {
             toh(a,c,b,n-1);

             int p=pop(a);
             push(b,p);

             toh(c,b,a,n-1);
            }
       }
コード例 #6
0
ファイル: tow_of_hanoi.c プロジェクト: sagar55/MyProg
main()
{
      int n;
      char S,T,D;
      printf("enter the no. of disk to move from S to D using T as intermediate\t");
      scanf("%d",&n);
      toh(n,'S','T','D');
      getch();
}
コード例 #7
0
ファイル: tower_of_hannoi.c プロジェクト: shivendr/Ccodes
       main()
       {
          Node *a,*b,*c;
          a=(Node*)malloc(sizeof(Node));
          b=(Node*)malloc(sizeof(Node));
          c=(Node*)malloc(sizeof(Node));
          a->next=b->next=c->next=0;

          int i,j;
          printf("Enter the number of digits of which tower of hannoi is to be solved. -->  ");
          scanf("%d",&j);
          for(i=j;i>=1;i--)
          push(a,i);

          toh(a,b,c,j);
          display(b);
       }