C程序看不懂

来源:百度知道 编辑:UC知道 时间:2024/06/06 13:31:46
有个C程序看不懂谁能给加个注释
程序
#include<stdio.h>
#define max 50
struct snode{
int data[max];
int top;
}s;
int n;

void stor()
{
s.top=-1;
}

void push(int q)
{
s.top++;
s.data[s.top]=q;
}

int pop()
{
int temp;
temp=s.data[s.top];
s.top--;
return temp;
}

int ept()
{
if(s.top==-1)
return 1;
else
return 0;
}

void result(int pos,int path[],int curp)
{
int m,i;
if(pos<n)
{
push(pos+1);
result(pos+1,path,curp);
pop();
}
if(!ept())
{
m=pop();
path[curp]=m;
curp++;
result(pos,path,curp);
push(m);
}
if(pos==n&&ept())
{
for(i=0;i<curp;i++)
printf("%2d",path[i]);
printf("\t");
}
}

void main()
{
int path[max];

printf("input the number:"

人家n是全局变量,已经定义过了,用不着再一次次定义吧...

#include<stdio.h>
#include<conio.h> //里面用到了getch();好象要引入<conio.h>

#define max 50 //设定结构体存储量

struct snode //定义结构体
{
int data[max];
int top;
}s;
int n; //全局变量

void stor() //函数1
{
s.top=-1;
}

void push(int q) //函数2
{
s.top++;
s.data[s.top]=q;
}

int pop() //函数3
{
int temp;
temp=s.data[s.top];
s.top--;
return temp;
}

int ept() //函数4
{
if(s.top==-1)
return 1;
else
return 0;
}

void result(int pos,int path[],int curp) // 函数5
{
int m,i;
if(pos<n) //首先判断pos跟输入的数字n之间的关系
{
push(pos+1);
result(pos+1,path,curp); //递归调用,每次pos的值加1,直到pos的值大于n;
pop(); //最后调用函数3;得到返回值