MyStack<char> *pStack = new MyStack<char>(30);
int mod = 0;
char modchar;
int N = 13548;
while (N != 0)
{
mod = N%HEXADECIMAL;
if (mod < 10)
{
modchar = mod + 48;
}
else
{ modchar = (mod - 10) + 'A'; }
pStack->push(modchar);
N /= HEXADECIMAL;
}
pStack->stackTraverse(false);
int mod = 0;
char modchar;
int N = 13548;
while (N != 0)
{
mod = N%HEXADECIMAL;
if (mod < 10)
{
modchar = mod + 48;
}
else
{ modchar = (mod - 10) + 'A'; }
pStack->push(modchar);
N /= HEXADECIMAL;
}
pStack->stackTraverse(false);
2016-12-24
老师最后一点其实错了,default 其实没有必要写,只要把pNeedStack->pop(currentNeed)改为
if(!pNeedStack->pop(currentNeed))
{
currentNeed=0;
}便够了,第一次输入“【()】】“显示错误是因为,循环到倒数第二个字符时,pNeedStack栈为空导致pNeedStack->pop(currentNeed)返回了一个false,currentNeed没有置于0,仍为”】“,导致循环到最后一个字符时str[4]==currentNeed,str[4]没有入栈,pStack最后为空才会出错.把crrentNeed置于0便好
if(!pNeedStack->pop(currentNeed))
{
currentNeed=0;
}便够了,第一次输入“【()】】“显示错误是因为,循环到倒数第二个字符时,pNeedStack栈为空导致pNeedStack->pop(currentNeed)返回了一个false,currentNeed没有置于0,仍为”】“,导致循环到最后一个字符时str[4]==currentNeed,str[4]没有入栈,pStack最后为空才会出错.把crrentNeed置于0便好
2016-11-19