汉诺塔非递归算法(Tower of Hanoi non recursive algorithm).docVIP

  • 7
  • 0
  • 约5.6千字
  • 约 20页
  • 2017-10-06 发布于河南
  • 举报

汉诺塔非递归算法(Tower of Hanoi non recursive algorithm).doc

汉诺塔非递归算法(Tower of Hanoi non recursive algorithm)

汉诺塔非递归算法(Tower of Hanoi non recursive algorithm) * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * about error process * / # include stdlib.h # include string.h # include stdio.h / * if debuging use # define error _ debug otherwise remove it. * / / / define error _ debug # # ifdef error _ debug # define error error _ debug (x) (x) # define report (report) _ debug () # define initerror initerror _ debug () () char * err [10]; int errs = 0; initerror _ debug (void) { int i; for (i = 0; i 10; i + +) that (i) = null; } void error (_ debug char *) { if (errs 9) return; this errs [] = (char *) malloc (strlen (a) + 1); strcpy (errs err [], (a); printf (a); errs + +; } _ debug void report () { int i; if (! errs) return; for (i = 0; i errs; i + +) { printf (err [i]); free (err [i]); } } # else # define error (x) # define report () # initerror (define) # endif / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * about stack * / # define stack _ size 31 typedef struct { data stack size _ int []; int top; stack}; int clear (stack *); create (int stack * *); push (stack * a, int int data); pop (stack * a, int * int data); int gettop (stack * * data, int); int dispose (stack *); int pop (stack * * data, int) { if (- top) { * = data - data - - - [top]; return 1; } else { error (pop (stack * *, int): stack is empty. i n ); return 0; } } push (stack * a, int {int data) if (top of the stack _ - size) { the data - - [top] = data + +; return 1; } else { error (push (stack *, int): a full stack. i n ); return 0; } } create (stack * * int) { * a = (stack *) malloc (sizeof (stack)); if (* a) and clear (*); else { error (create (stack * *): create error! momery is not enough. i n ); return 0; } } int clear (stack *) { if (a) { the top - = 0; return 1; } else { error (clear: stack (stack *) is not exist. i n ); return 0; } } int gettop (stack * * data, int) { if (- top) { data = a * - - top data [1]; return

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档