Paths* clone() { Paths* ps = new Paths(); for (int i=0;i<this->size();i++) { ps->push(paths[i]->clone()); } return ps; }
Paths* getPathFrom(string c) { Paths* ps = new Paths(); for (int i=0; i<paths.size(); i++) { if (paths[i]->c1 == c || paths[i]->c2 == c) { ps->push(paths[i]); } } return ps; }
int main(int argc, char** argv) { int n, m; int val; string c, c1, c2; // initialize & input cin>>n>>m; Citys citys(n); Paths paths; SpanningPaths spanning_path; for(int i=0;i<n;i++) { cin >> c; citys.setName(i, c); } for(int i=0;i<m;i++) { cin>>c1>>c2>>val; paths.push(new Path(c1, c2, val)); } // kruskal's algo paths.sortByCost(); for (int i=0; i<paths.size(); i++) { Path* p = paths.at(i); if (!spanning_path.existRingIfAdd(p)) { spanning_path.push(p->clone()); } } int total_cost = 0; for (int i=0; i<spanning_path.size(); i++) { Path* p = spanning_path.at(i); cout << "(" << p->c1 << " " << p->c2 << ") "; total_cost += p->cost; } cout << "\n" << total_cost << endl; // paths.list(); // spanning_path.list(); return 0; }
void SolveDir( fs::path & dirName) { // Get all files in this dir // loop through them LOG( "Entering DIRECTORY: " << dirName); fs::directory_iterator end_iter; for ( fs::directory_iterator dir_itr( dirName ); dir_itr != end_iter; ++dir_itr ) { // if it is subdir, call itself on subdir if ( fs::is_directory( dir_itr->status() ) ) { paths.push( *dir_itr); } else { entryCont.SolveFile( dir_itr->string(), dirName.string() ); } } }
int main( int argc, char** argv) { fs::path full_path( fs::initial_path<fs::path>() ); if ( argc > 1 ) full_path = fs::system_complete( fs::path( argv[1], fs::native ) ); else PrintUsage(); // specification of hi, low date of studies if( argc > 2) { string s(argv[2]); if( s.compare( "--info") == 0 ) { entryCont.infoOnly = true; } else { if( argc > 3) { entryCont.dateFrom = argv[2]; entryCont.dateTo = argv[3]; } else PrintUsage(); } } // recursively (through queue) go through all files in subtree // of specified directory specified try { if ( fs::is_directory( full_path ) ) { paths.push( full_path); } else // must be a file { entryCont.SolveFile( full_path.string(), "buddy" ); } fs::path currPath; while( ! paths.empty() ) { currPath = paths.front(); SolveDir( currPath); paths.pop(); // remove this dir from queue } } catch( std::exception &ex) { LOG( ex.what()); } // flush info { ofstream o("output.txt"); entryCont.FlushMaps( o); o.close(); } return 0; }