2017亚马逊在线笔试题目
str.append("push");
sprintf(tmp, "%d", originalArray[i]);
str.append(tmp);
str.append("|");
i++;
while (!st.empty())
{
if (j < length && st.top() == resultArray[j])
{
str.append("pop");
sprintf(tmp, "%d", resultArray[j]);
str.append(tmp);
str.append("|");
st.pop();
j++;
if (i < length)
{
st.push(originalArray[i]);
str.append("push");
sprintf(tmp, "%d", originalArray[i]);
str.append(tmp);
str.append("|");
i++;
}
}
else
{
if (i < length)
{
st.push(originalArray[i]);
str.append("push");
sprintf(tmp, "%d", originalArray[i]);
str.append(tmp);
str.append("|");
i++;
}
else
break;
}
}
if (!st.empty())
return NULL;
char *p = (char *)malloc(1 + str.length());
if (NULL != p)
{
strcpy(p, str.c_str());
p[str.length() - 1] = '\0';
return p;
}
return NULL;
}