-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathList.cpp
More file actions
75 lines (68 loc) · 1.9 KB
/
Copy pathList.cpp
File metadata and controls
75 lines (68 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// List.cpp
// Project3
//
// Created by Rumeysa Bulut on 30.11.2017.
// Copyright © 2017 Rumeysa Bulut. All rights reserved.
//
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <ctime>
#include <algorithm>
#include "List.hpp"
List::List(){
ifstream inputFile;
inputFile.open("ds-set-input.txt");
if(!inputFile){
cout<< "Error opening input file" << endl;
return;
}
clock_t start = clock();
block_insertion(inputFile);
clock_t end = clock();
double elapsed_time = double (end - start) / CLOCKS_PER_SEC;
cout << "Insertion finished after :" << elapsed_time << " seconds" << endl;
start = clock();
block_lookup();
end = clock();
elapsed_time = double (end - start) / CLOCKS_PER_SEC;
cout << "Lookup finished after :" << elapsed_time << " seconds" << endl;
inputFile.close();
}
void List::block_insertion(ifstream &inputFile){
BookCharacter bookch;
string line;
while(getline(inputFile, line)){
bookch = BookCharacter(line);
characterList.push_back(bookch);
}
}
void List::block_lookup(){
BookCharacter wanted;
list<BookCharacter>::iterator findit;
ifstream lookupFile;
ofstream lookupOut;
lookupFile.open("ds-set-lookup.txt");
lookupOut.open("ds-set-output-list.txt");
if(!lookupFile){
cout<< "Error opening input file" << endl;
return;
}
string line;
findit = characterList.begin();
while(getline(lookupFile, line)){
wanted = BookCharacter(line);
for(int i = 0; i < characterList.size(); i++){
if(findit->getKey() != wanted.getKey()){
findit++;
}
else{
lookupOut << line << '\t' << findit->getCharacter() << endl;
findit = characterList.begin();
break;
}
}
}
}