文档介绍::
long fact ( long n )
{
if ( n == 0 ) return 1;
else return n * fact (n-1);
}
:
int f(int n)
{
int i,s,s1,s2;
s1=1; /*s1用于保存f(n-1)的值*/
s2=1; /*s2用于保存f(n-2)的值*/
s=1;
for (i=3;i<=n;i++)
{
s=s1+s2;
s2=s1;
s1=s;
}
return(s);
}
:
#define n 100
typedef struct node
{
char data;
struct node *left,*right;
}bitree;
int counter(bitree * t)
{
bitree *stack[n],*node;
int top,count=0;
if (t!=NULL)
{
top=1;
stack[top]=t;
while (top>0)
{
count++;
node=stack[top];
top--;
if (node->left!=NULL)
{
top++;
stack[top]=node->left;
}
if (node->right!=NULL)
{
top++;
stack[top]=node->right;
}
} /*end of while */
} /*end of if */
return(count);
}
:
int path(int maze[m][n],item move[8])
{
Stack s;
INISTACK(&s);
datatype temp;
int x,y,d,i,j;
=1;=1;=-1;
PUSH(&s,temp) ;
while(!EMPTY(&s))
{
temp=POP(&s);
x=;y=;d=+1;
while(d<8)
{
i=x+move[d].x;
j=y+move[d].y;
if(maze[i][j]==0)
{
=x;=y;=d;
PUSH(&s,temp);
x=i;y=j;maze[x][y]=-1;
if(x==m&&y==n)
return 1; /*迷宫有路*/
else d=0 ;
}
else
d++;
} /*while (d<8)*/
} /*while */
return 0;/*迷宫无路*/
}
:
void hanoi(int n,char s,char m,char e)
{ //将头栓s上由小到大且编号为1至n的n个盘子按规则搬到尾栓e上,
//中栓m可用来辅助搬运
if (n==1)
move(s,1,e);//将编号为1的盘子从头栓S移到尾栓E