Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "StudentList.h"
- #include<string>
- #include<vector>
- #include<list>
- #include<fstream>
- #include<random>
- #include<chrono>
- #include<algorithm>
- using namespace std;
- std::vector<int> ids;
- std::vector<string> StudentNames;
- StudentList::StudentList(string FileName) {
- ifstream myFile;
- myFile.open(FileName);
- char delim = ',';
- string s;
- while (getline(myFile, s, delim)) {
- StudentNames.push_back(s);
- }
- GenerateRandomIDs(ids, StudentNames.size);
- for (int i = 0; i < ids.size; i++) {
- Student *st = new Student(ids[i], StudentNames[i]);
- Student_List.push_back(*st);
- Student_Vector.push_back(*st);
- }
- }
- double StudentList::sort_vector() {
- chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now();
- std::sort(Student_Vector.begin(), Student_Vector.end());
- chrono::high_resolution_clock::time_point t2 = chrono::high_resolution_clock::now();
- chrono::duration<double> time_span = chrono::duration_cast<chrono::duration<double>>(t2 - t1);
- return time_span.count();
- }
- double StudentList::search_vector_by_id(int id) {
- chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now();
- std::find(ids.begin, ids.end, id);
- chrono::high_resolution_clock::time_point t2 = chrono::high_resolution_clock::now();
- chrono::duration<double> time_span = chrono::duration_cast<chrono::duration<double>>(t2 - t1);
- return time_span.count();
- }
- double StudentList::sort_list() {
- chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now();
- std::sort(Student_List.begin(), Student_List.end());
- chrono::high_resolution_clock::time_point t2 = chrono::high_resolution_clock::now();
- chrono::duration<double> time_span = chrono::duration_cast<chrono::duration<double>>(t2 - t1);
- return time_span.count();
- }
- double StudentList::search_list_by_id(int id) {
- chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now();
- std::sort(Student_List.begin(), Student_List.end());
- chrono::high_resolution_clock::time_point t2 = chrono::high_resolution_clock::now();
- chrono::duration<double> time_span = chrono::duration_cast<chrono::duration<double>>(t2 - t1);
- return time_span.count();
- return 0;
- }
- ostream& operator<<(ostream& os, const StudentList& sl) {
- for (int i = 0; i < StudentNames.size; i++) {
- os << StudentNames[i];
- }
- return os;
- }
- static void GenerateRandomIDs(vector<int>& ids, const int number_of_ids) {
- int r;
- for (int i = 0; i < number_of_ids; i++) {
- //give random r
- do {
- r = 1 + (rand() % static_cast<int>(number_of_ids));
- }while (std::find(ids.begin, ids.end, r) = ids.end);
- ids.push_back(r);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement