void legalstack(tack* st, int in[], int out[], int len, int i, int j)
{
int x;
static int num = 1;
if (empty(st) && j >= len)
{
cout << "第" << num++ << "种 : ";
for (int i = 0; i < len; i++)
{
cout << out[i] << " ";
}
cout << endl;
}
else if (empty(st) == false && i < len)
{
x = gettop(st);
pop(st);
out[j] = x;
legalstack(st, in, out, len, i, ++j);
j--;
push(st,x);
push(st, in[i]);
legalstack(st, in, out, len, ++i, j);
i--;
pop(st);
}
else if (empty(st) == false && i >= len)
{
x = gettop(st);
pop(st);
out[j] = x;
legalstack(st, in, out, len, i, ++j);
j--;
push(st, x);
}
else if (empty(st) == true && i < len)
{
push(st, in[i]);
legalstack(st, in, out, len, ++i, j);
i--;
pop(st);
}
}
标签:legalstack,出栈,int,len,st,pop,序列,合法,out
From: https://blog.csdn.net/2301_80035407/article/details/137179464