Hannota (Stack)

xiaoxiao2021-03-05  40

Class Hanoi {Friend Void Towersofhanoi (int); public: void Towersofhanoi (int N, int x, int y, int z); private: stack * s [4];}; // Put N discs from the tower X Move to Tower Y, can be used with Tag Zvoid Hanoi :: Towersofhanoi (Int N, INT X, INT Y, INT Z) {INT D; IF (N> 0) {Towersofhanoi (N-1, X, Z, Y) ; // drill away from X] -> delete (d); // Put this dish in y on Y s [y] -> add (d); showstate (); Towersofhanoi (N-1 , Y, X);}} void Towersofhanoi (INT N) {Hanoi X; XS [1] = New Stack (N); XS [2] = New Stack (n); xs [ 3] = new stack (n); // Put the disc from the large to small into the tower 1 for (int D = N; D> 0; D ) XS [1] -> Add (d); x. Towersofhanoi (N, 1, 2, 3);

Ref: << Data Structure, Algorithm & Applications >> P170 ~ 172

转载请注明原文地址:https://www.9cbs.com/read-32240.html

New Post(0)