int ifornot(int input[], int output[],int length)
{
Stack s;
Init(s);
int a =0, e, b = 0;
if (!same(input, output, length))
return 0;
for (int i = 0; i < length; i++)
{
if (i == 0)
{
b = Get(input, output[i], length);
for (int j = 0; j <= b; j++)
push(s, input[j]);
pop(s, e);
a++;
}
else if (output[i] == GetTop(s))
{
while (GetTop(s) >= output[i])
{
pop(s, e);
a++;
}
}
else if (output[i] > GetTop(s))
{
for (int j = b + 1; j < Get(input, output[i], length); j++)
push(s, input[j]);
pop(s, e);
a++;
b = Get(input, output[i], length);
}
else if (output[i] <= GetTop(s))
return 0;
else
return 0;
}
return a;
}
当开始没有给a初始化的时候,出现报错
Run-Time Check Failure #3 - The variable ‘a’ is being used without being initialized.
存在问题:
1.将a初始化之后不再报错,但整个程序完成后将初始化操作删掉又不报错
2.该函数是为了解决判断所给出栈顺序是否与能实现问题,但当前程序只能判断输入序列为递增有序数列,对于无序数列不能够正确判断