Question: Stuck on a program in C++ please help... I have finished the majority of a large program successfully, but one part is giving me a
Stuck on a program in C++ please help...
I have finished the majority of a large program successfully, but one part is giving me a really hard time....
The program is a binary search tree, and so far my program works as intended with the following inputs

and it works correctly with...

The output looks like...

But when the first two or more characters are operators I get a segmentation fault. The following input causes a seg fault...

I just need to rewrite the code I have so that it can account for the different file input. There is a lot of code, but clearly the majority of the code works, so I will only include the portions of the code that reads in the file and sends the data on to the binary tree. I will include the main.cpp and the Executive.h and Executive.cpp. Main does nothing except check for the correct number of starting parameters and passes the name of the file to open to Executive. Executive then opens the file and reads the content into the tree, and afterwards displays the contents in terminal....
main.cpp
#include
#include "Executive.h"
#include "Executive.cpp"
int main(int argc, char* argv[]){
if(argc
std::cout
exit(0);
}
else{
string filename = "postfix2.txt";
Executive exec;
exec.run(filename);
}
return(0);
}
Executive.h
#ifndef EXECUTIVE_H
#define EXECUTIVE_H
#include
#include
#include
#include "BinaryNodeTree.h"
#include "LinkedStack.h"
using namespace std;
class Executive
{
public:
Executive();
~Executive();
void run(string filename);
private:
BinaryNodeTree
static void visit(string& myItem);
void printTreePreorder(BinaryNodeTree
void printTreeInorder(BinaryNodeTree
void printTreePostorder(BinaryNodeTree
};
#endif
Executive.cpp
#include "Executive.h" using namespace std; Executive::Executive(){ } void Executive::run(string filename){ ifstream file; file.open(filename); LinkedStack
std::cout * operands = new BinaryNodeTree The problem lies in the run function... void Executive::run(string filename){ ifstream file; file.open(filename); LinkedStack std::cout * operands = new BinaryNodeTree PLEASE HELP!!!! Will give a thumbs up and comments if the program works for both files!!!!!!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
