-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinked_list.h
274 lines (263 loc) · 6.06 KB
/
linked_list.h
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#include <iostream>
#include <string.h>
#include <memory>
const int prior1 = 700;
const int prior2 = 600;
const int prior3 = 500;
const int prior4 = 400;
const int prior5 = 300;
const int prior6 = 200;
const int prior7 = 100;
struct node
{
std::string sno;
std::string time;
std::string source;
std::string destination;
std::string protocol;
std::string length;
std::string info;
int key;
node *right;
node *left;
};
void display(node *n)
{
std ::cout << n->sno << " " << n->time << " " << n->source << " " << n->destination << " " << n->protocol << " " << n->length << " " << n->info << endl;
std ::cout << "PACKET PRIORITY : " << n->key << endl;
}
void save_copy(node *n1, node *n2)
{
strcpy(n1->sno, n2->sno);
strcpy(n1->time, n2->time);
strcpy(n1->source, n2->source);
strcpy(n1->destination, n2->destination);
strcpy(n1->protocol, n2->protocol);
strcpy(n1->length, n2->length);
strcpy(n1->info, n2->info);
n1->key = n2->key;
}
void exchange(node *n1, node *n2)
{
std::string sno;
std::string time;
std::string source;
std::string destination;
std::string protocol;
std::string length;
std::string info;
strcpy(sno, n1->sno);
strcpy(time, n1->time);
strcpy(source, n1->source);
strcpy(destination, n1->destination);
strcpy(protocol, n1->protocol);
strcpy(length, n1->length);
strcpy(info, n1->info);
strcpy(n1->sno, n2->sno);
strcpy(n1->time, n2->time);
strcpy(n1->source, n2->source);
strcpy(n1->destination, n2->destination);
strcpy(n1->protocol, n2->protocol);
strcpy(n1->length, n2->length);
strcpy(n1->info, n2->info);
strcpy(n2->sno, sno);
strcpy(n2->time, time);
strcpy(n2->source, source);
strcpy(n2->destination, destination);
strcpy(n2->protocol, protocol);
strcpy(n2->length, length);
strcpy(n2->info, info);
int k = n1->key;
n1->key = n2->key;
n2->key = k;
}
node *create_node(char *sent)
{
node *n = std::unique_ptr<node>();
std::string del = ",";
std::string no = strtok(sent, del);
std::string ti = strtok(nullptr, del);
std::string sour = strtok(nullptr, del);
std::string dest = strtok(nullptr, del);
std::string prot = strtok(nullptr, del);
std::string len = strtok(nullptr, del);
std::string inf = strtok(nullptr, del);
n->sno = no;
n->time = ti;
n->source = sour;
n->destination = dest;
n->protocol = prot;
n->length = len;
n->info = inf;
if (n->protocol == "\"TCP\"")
{
// std :: cout<<"\n------Packet Priority 1-------\n";
n->key = prior1--;
if (prior1 == 600)
{
prior1 = 700;
}
}
else if (n->protocol == "\"TLsv1\"")
{
// std :: cout<<"\n------Packet Priority 2-------\n";
n->key = prior2--;
if (prior2 == 500)
{
prior2 = 600;
}
}
else if (n->protocol == "\"SSDP\"")
{
// std :: cout<<"\n------Packet Priority 3-------\n";
n->key = prior3--;
if (prior3 == 400)
{
prior3 = 500;
}
}
else if (n->protocol == "\"NBNS\"")
{
// std :: cout<<"\n------Packet Priority 4-------\n";
n->key = prior4--;
if (prior4 == 300)
{
prior4 = 400;
}
}
else if (n->protocol == "\"QVIC\"")
{
// std :: cout<<"\n------Packet Priority 5-------\n";
n->key = prior5--;
if (prior5 == 200)
{
prior5 = 300;
}
}
else if (n->protocol == "\"MDNS\"")
{
// std :: cout<<"\n------Packet Priority 6-------\n";
n->key = prior6--;
if (prior6 == 100)
{
prior6 = 200;
}
}
else
{
// std :: cout<<"\n------Packet Priority 7-------\n";
n->key = prior7--;
if (prior7 == 0)
{
prior7 = 100;
}
}
n->left = nullptr;
n->right = nullptr;
}
class linked_list
{
int count = 0;
node *start = nullptr;
node *end = nullptr;
public:
linked_list();
int get_count();
void insert_end(char *);
void delete_last();
int operator[](int);
int get_key();
void display();
node *get_node(int);
void set_key(int, int);
};
int linked_list::get_key()
{
return end->key;
}
void linked_list::set_key(int key, int index)
{
node *n = get_node(index);
n->key = key;
}
int linked_list::get_count()
{
return count;
}
void linked_list::insert_end(char *sent)
{
count++;
node *n = create_node(sent);
if (start == nullptr)
{
start = n;
end = n;
return;
}
end->right = n;
n->left = end;
end = n;
}
void linked_list::delete_last()
{
if (count == 1)
{
start = end = nullptr;
count--;
}
else if (end != nullptr)
{
end = end->left;
end->right = nullptr;
count--;
}
}
int linked_list::operator[](int index)
{
if (index <= 1)
{
return start->key;
}
else if (index >= count)
{
return end->key;
}
node *n = start;
index = index - 1;
while (index > 0 && n != nullptr)
{
n = n->right;
index--;
}
return n->key;
}
void linked_list::display()
{
node *n = start;
while (n != nullptr)
{
std ::cout << "[" << n->protocol << "-" << n->sno << "-" << n->key << "]"
<< "\n";
n = n->right;
}
std ::cout << "nullptr" << endl;
}
node *linked_list::get_node(int index)
{
if (index <= 1)
{
return start;
}
else if (index >= count)
{
return end;
}
node *n = start;
index--;
while (index > 0 && n != nullptr)
{
n = n->right;
index--;
}
return n;
}