int main(){ FileIO * file = new FileIO("tube.txt"); vector<Station *> station_list = file->read_file_to_station_list(); vector<Station *> sorted_list = file->read_file_to_station_list(); std::sort(sorted_list.begin(), sorted_list.end(), sort_by_name); // print_all(sorted_list, station_list); // search_by_keyword(sorted_list, station_list); // mode_selection(sorted_list, station_list); //test section node<int> *_node = new node<int>(); // cout<<sorted_list[0]->get_station_index()<<endl; _node->data = sorted_list[0]->get_station_index(); AVL<int> *tree = new AVL<int>(_node); //new binary_tree<int>(_node); for(vector<Station *>::iterator it = sorted_list.begin() + 1;it != sorted_list.end();++it){ bool b_return = tree->insert((*it)->get_station_index()); // cout<<(*it)->get_station_index()<<" "<<b_return<<endl; } cout<<"done!"<<endl; // tree->traverse_inorder(tree->root); cout<<"Tree height is "<<tree->tree_height<<endl; node<int> *returned_node = tree->search(0); cout<<returned_node->data<<" "<<returned_node->height<<endl; node<int> *rhs = tree->root; // cout<<rhs->data<<" "<<rhs->height<<endl; rhs = rhs->rhs; node<int> min, max; // cout<<"d 1"<<endl; tree->find_min_from(rhs, min); // cout<<"d 2"<<endl; tree->find_max_from((tree->root)->lhs, max); cout<<"min in right branch is "<<min.data<<" "<<min.height<<endl; cout<<"max in left branch is "<<max.data<<" "<<max.height<<endl; cout<<"depth is "<<tree->find_depth(tree->root)<<endl; cout<<"left branch depth is "<<tree->find_depth((tree->root)->lhs)<<endl; cout<<"right branch depth is "<<tree->find_depth((tree->root)->rhs)<<endl; cout<<"balance factor is "<<tree->balance_factor(tree->root)<<endl; cout<<"tree is balanced? "<<tree->is_balanced(tree->root)<<endl; cout<<"tree root "<<(tree->root)->data<<endl; // delete[] tree->root; delete tree; return 0; }
int main(){ FileIO * file = new FileIO("tube.txt"); vector<Station *> station_list = file->read_file_to_station_list(); vector<Station *> sorted_list = file->read_file_to_station_list(); std::sort(sorted_list.begin(), sorted_list.end(), sort_by_name); // print_all(sorted_list, station_list); // search_by_keyword(sorted_list, station_list); mode_selection(sorted_list, station_list); //test section /* int start, end; Station * result_station, *start_p, *end_p; cout<<"Start: "; cin>>start; cout<<"End: "; cin>>end; if(station_validation(station_list, start) && station_validation(station_list, end)){ cout<<endl; find_index(station_list, start_p, start); find_index(station_list, end_p, end); cout<<"Start from "<<start_p->get_station_name()<<" to "<<end_p->get_station_name()<<endl; vector<int> result_path = A_star_start(station_list, start, end); for(vector<int>::iterator it = result_path.begin();it != result_path.end() - 1;++it){ find_index(station_list, result_station, *it); cout<<result_station->get_station_name()<<"->"; } cout<<end_p->get_station_name()<<endl; cout<<result_path.size()<<" stations in total."<<endl; } */ return 0; }