c program to implement oprations on tower of hanoi

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sekitoleko
    New Member
    • Sep 2006
    • 21

    c program to implement oprations on tower of hanoi

    This operation involves push/pop operations on a stack,arranging the smaller discs to sit on larger ones.How can I write a program to implement this?
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Use linked lists to create your stack.

    Comment

    • jessy
      New Member
      • Oct 2006
      • 106

      #3
      here's the code hunny ...

      it took me 4 hours to get it ...tracing this code is like hell

      # include <iostream.h>
      # .....

      void towers(int n,char frompeg,char topeg,char auxpeg)

      {
      if(n==1) //if only one disk just make the move and return
      {
      cout<<"\n"<<"mo ve disk 1 from peg"<<frompeg<< "to peg"<<topeg<<"\ n";
      return;
      }
      towers(n-1,frompeg,auxpe g,topeg);
      cout<<"\n"<<"mo ve disk"<<" "<<n<<"from peg"<<frompeg<< "to peg"<<topeg<<"\ n;

      towers(n-1,auxpeg,topeg, frompeg);

      }

      void main()
      { int n;
      cout<<"enter no of disks 2 be moved "<<endl;
      cin>>n;
      towers(n,'A','C ','B');
      getch();

      }

      Comment

      Working...