-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdequeaslisttest.cpp
134 lines (109 loc) · 3.16 KB
/
dequeaslisttest.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Driver Class
#include "BrowserHistory.h"
#include "WebsiteData.h"
#include <iostream>
#include <string>
using namespace std;
int main() {
std::string line;
BrowserHistory h;
bool error;
while (true) {
if (cin.eof()) {
break;
}
getline(cin, line);
if (line == "exit") {
break;
}
int pos = line.find(" ");
std::string cmd = line.substr(0, pos);
std::string obj = line.substr(pos + 1);
if (cmd == "push_back") {
pos = obj.find("\"");
obj = obj.substr(pos+1);
pos = obj.find("\"");
string urlName = obj.substr(0,pos);
obj = obj.substr(pos+1);
pos = obj.find("\"");
obj = obj.substr(pos+1);
pos = obj.find("\"");
string url = string(obj.substr(0,pos));
h.push_back(urlName, url);
cout << "success"<<endl;
}
if (cmd == "pop_front") {
error = h.pop_front();
if (error) {
cout << "success"<<endl;
} else {
cout <<"failure"<<endl;
}
}
if (cmd == "pop_back") {
error = h.pop_back();
if (error) {
cout << "success"<<endl;
} else {
cout <<"failure"<<endl;
}
}
if (cmd == "push_front") {
pos = obj.find("\"");
obj = obj.substr(pos+1);
pos = obj.find("\"");
string urlName = obj.substr(0,pos);
obj = obj.substr(pos+1);
pos = obj.find("\"");
obj = obj.substr(pos+1);
pos = obj.find("\"");
string url = string(obj.substr(0,pos));
h.push_front(urlName, url);
cout << "success"<<endl;
}
if (cmd == "size") {
int size = h.size();
cout<< "size is ";
cout<<size<<endl;
}
if (cmd == "front") {
WebsiteData * front = h.front();
if (front != NULL) {
cout<< "front is " + front->name + " " + front->url<<endl;
} else {
cout<<"failure"<<endl;
}
}
if (cmd == "back") {
WebsiteData * back = h.back();
if (back != NULL) {
cout<< "back is " + back->name + " " + back->url<<endl;
} else {
cout<<"failure"<<endl;
}
}
if (cmd == "empty") {
cout<<h.empty()<<endl;
}
if (cmd == "clear") {
h.clear();
cout<<"success"<<endl;
}
if (cmd == "find") {
pos = obj.find("\"");
obj = obj.substr(pos+1);
pos = obj.find("\"");
string urlName = obj.substr(0,pos);
WebsiteData * data = h.find(urlName);
if (data != NULL) {
cout << "found " + data->name + " " + data->url<<endl;
} else {
cout <<"not found " + urlName<<endl;
}
}
if (cmd == "print") {
h.print();
}
}
return 0;
}