[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A programing Q.



Hi,

It may be a little off topic but since it started as en effort to learn
Linux debugging tools and since I know many of you are programmers pleas
excuse me for asking it here.

It concerns the classic question of the Hanoi Towers.
If you don't know what is the Hanoi Towers look at :
http://www.cs.cmu.edu/~cburch/survey/recurse/index.html

Now the classic question ask of you to tell the user what to move when
in order to solve the Towers and the code for that is :

void Do_Hanoi (int  N,char *from, char *inter char *to)
{
     if (N==1)
            cout<<“Disk 1”<< “from”<<from<< “ to “<< to << endl;
     else
     {
            Do_Hanoi (N - 1,from,to,inter)
            cout << “Disk ” << N << “ from”<< from<< “to ”<<to;
            Do_Hanoi (N - 1,inter, from,to);
     }
}

Where N is the number of disks and the three (char *)s are the names of
the three towers hence. "a", "b", "c".

So far so good but, what we need to do is  :
Without changing the procedure's header. meaning without changing "void
Do_Hanoi (int  N,char *from, char *inter char *to)" we need to print the
status of the towers every time we make a change.

Knowing where disk n is and where all the disks smaller then n is easy
but how do we know where the disks which are larger then n are ?

Have fun.

Erez

--
      /'^'\
     ( o o )
-oOOO--(_)--OOOo--------------------------------------------------
Erez Boym
57 Shkedim St', P.O.Box 4480.
K' Tivon, 36501
, ISRAEL
Fax - +972 4 8316876
ICQ# - 3015118
Email home: ehboym@internet-zahav.net
  work: erezb@elbit.co.il
www - http://www.geocities.com/thetropics/6045/index.html
    .oooO
    (   )   Oooo.
-----\ (----(   )-------------------------------------------------
      \_)    ) /
            (_/