我正在为我的数据结构类创建自己的堆栈.对于我们的任务,我们使用赋值将实时中缀方程转换为后缀方程.
我认为我的程序:
输入
确定它是否为数字或数字(操作数)
打印输出
确定输入是否为运算符(+, - ,/,*)
添加到堆栈或打印输出,具体取决于堆栈优先级
相反,它会按预期打印出操作数,但是当我进入运算符时出现此错误
>.../dorun.sh line 33: 4136 Segmentation fault <core dumped> sh "$<SHFILE>"
#include <vector>
using namespace std;
class DishWell{
public:
char ReturnEnd(){
return Well.back();
}
void Push(char x){
Well.push_back(x);
}
void Pop(){
Well.pop_back();
}
bool IsEmpty(){
return Well.empty();
}
private:
vector<char> Well;
};
#include <iostream>
bool Precidence(char Input, char Stack){
int InputPrecidence,StackPrecidence;
switch (Input){
case '*':
InputPrecidence = 4;
break;
case '/':
InputPrecidence = 4;
break;
case '+':
InputPrecidence = 3;
break; …Run Code Online (Sandbox Code Playgroud) #include "Iobuffer.h"
IOBuffer::IOBuffer (int maxBytes){
Init (maxBytes);
}
IOBuffer & IOBuffer :: operator = (const IOBuffer & buffer){
if(MaxBytes< buffer.BufferSize) return *this;//fail
Initialized = buffer.Initialized;
BufferSize = buffer.BufferSize;
memcpy(Buffer, buffer.Buffer, buffer.BufferSize);
NextByte = buffer.NextByte;
Packing = Packing;
return *this;
}
void IOBuffer::Clear(){
NextByte = 0;
Packing = true;
}
void IOBuffer::Print(ostream & stream) const{
stream<<"MaxBytes "<<MaxBytes<<" BufferSize "<<BufferSize;
}
int IOBuffer::Init (int maxBytes){
Initialized = false;
if (maxBytes < 0) maxBytes = 0;
MaxBytes = maxBytes;
Buffer = new …Run Code Online (Sandbox Code Playgroud) header.h
#include <iostream>
#include <vector>
class CombatLine{
std::stringstream Line;
std::vector<std::string> TokenLine;
void SetLine(std::string s){
Line<<s;
}
public:
void SetTokenLine(){
int i=0;
while(i<5){
Line>>TokenLine[i];
i++;}
TokenLine.resize(i);
for(int j=0;j<5;j++)
cout<<TokenLine[j];}
Run Code Online (Sandbox Code Playgroud)
main.cpp中
#include "Header.h"
using namespace std;
int main () {
CombatLine Line1;
Line1.SetLine("[Combat] A bird attacks -Anthrax- and misses (dodge).");
Line1.SetTokenLine();
}
Run Code Online (Sandbox Code Playgroud)
这构建但我收到此运行时错误, /cygdrive/C/Program Files/NetBeans 6.9.1/ide/bin/nativeexecution/dorun.sh: line 33: 4500 Segmentation fault <core dumped> sh "$<SHFILE>"
我知道它与我在SetTokenFile中操作字符串和流的方式有关,但我似乎无法确定是什么.
这是一个较大项目的一小部分.总的来说,我将解析一个动态文本文件,然后对整个文件的内容进行比较.