【发布时间】:2019-11-26 10:08:37
【问题描述】:
当我使用堆栈来简化我的目录路径时,我试图解决我的分段错误。但我似乎找不到任何会导致问题的东西。我错过了什么吗?
string Solution::simplifyPath(string A) {
string a="";
stack<char> one;
stack<char> res;
for(int i=0; i<A.length();i++){
one.push(A[i]);
}
one.pop();
while(one.top()!='/'){
res.push(one.top());
one.pop();
}
res.push('/');
while(res.top()!=NULL){
a+=res.top();
res.pop();
}
return a;
}
Error message:
Runtime Error. Your submission stopped because of a runtime error. ex: division by zero, array index out of bounds, uncaught exception You can try testing your code with custom input and try putting debug statements in your code.
Segmentation fault.
【问题讨论】:
-
你是在调试器中运行的吗?
-
如果
one中没有'/',while(one.top()!='/')会发生什么? -
@Riataro 在我看来这个功能没有意义。:)
标签: c++ segmentation-fault stack