再熟悉不过的数据结构了,也是普遍的一个基础
贴代码~~~
#define MAXSIZE 10
typedef struct
{
int data[MAXSIZE];
int top;
}SqStack;
SqStack sqt;
int total=4;
void InitStack(SqStack &st)
{
st.top=-1;
}
int StackEmpty(SqStack st)
{
return (st.top==-1);
}
int push(SqStack &st,int x)
{
if(st.top==MAXSIZE-1)
return 0;
st.top++;
st.data[st.top]=x;
return 1;
}
int pop(SqStack &st,int& x)
{
if(st.top==-1)
return 0;
x=st.data[st.top];
st.top--;
return 1;
}
int getTop(SqStack st)
{
return st.data[st.top];
}
void process(int pos,int path[],int curp)
{
int m,i,x;
if(pos<=total)
{
push(sqt,pos);
process(pos+1,path,curp);
pop(sqt,x);
}
if(!StackEmpty(sqt))
{
pop(sqt,m);
path[curp]=m;
curp++;
process(pos,path,curp);
push(sqt,m);
}
if(pos>total && StackEmpty(sqt))
{
printf(" ");
for(i=0;i<curp;i++)
printf("%d ",path[i]);
printf("/n");
}
}
然后来评价这自己写的代码
----------------------------------------
兼容性太差,风格不好,丫丫··~~~~