Skip to content
This repository has been archived by the owner on Mar 30, 2021. It is now read-only.

Project for CS24: Given text files containing movie names and ratings, the code implements a binary search tree that stores this information and allows the use of a variety of search functions to find specific movies. The big-O runtime is also analyzed for each individual type of search used.

Notifications You must be signed in to change notification settings

chrisstasiowski01/pa02_cs24

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#include #include #include #include #include #include #include

using namespace std;

bool parseLine(string &line, string &movieName, double &movieRating);

int main(int argc, char** argv){ if(argc < 4){ cerr << "Usage: " << argv[ 0 ] << "arg1 arg2 arg3" << endl; exit(1); }

bool flag = false; if(strcmp(argv[1], "true") == 0){ flag = true; } else if(strcmp(argv[1], "false") == 0) { flag = false; } else { cerr << "Argument 1 must be a boolean (true/false)" << endl; exit(1); }

ifstream movieFile (argv[2]); string line, movieName; double movieRating;

if (movieFile.fail()){ cerr << "Could not open file " << argv[2]; exit(1); }

// Create an objects of the BST class you defined // to contain the name and rating in the input file

// Read each file and store the name and rating while (getline (movieFile, line) && parseLine(line, movieName, movieRating)){ // Use std::string movieName and double movieRating // to construct your Movie objects cout << movieName << " has rating " << movieRating << endl; } movieFile.close();

return 0; }

bool parseLine(string &line, string &movieName, double &movieRating) { if(line.length() <= 0) return false; string tempRating = "";

bool flag = false; movieName = tempRating = "", movieRating = 0.0, flag = false;

for (int i = 0; i < line.length(); i++){ if(flag) tempRating += line[i]; else if(line[i]==','&& line[0]!='"') flag = true; else { if(i==0 && line[0]=='"') continue; if(line[i]=='"'){ i++; flag=true; continue;} movieName += line[i]; } }

movieRating = stod(tempRating); return true; }

About

Project for CS24: Given text files containing movie names and ratings, the code implements a binary search tree that stores this information and allows the use of a variety of search functions to find specific movies. The big-O runtime is also analyzed for each individual type of search used.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published