-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebsiteList.cpp
126 lines (101 loc) · 2.48 KB
/
WebsiteList.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
//
// Created by Sparsh on 2/5/2021.
// Linked List Class
#include "WebsiteList.h"
#include "BrowserHistory.h"
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
WebsiteList::WebsiteList() {
tail = NULL;
head = NULL;
current = NULL;
//prev = NULL;
}
void WebsiteList::setNext(string name, string url) {
WebsiteData * data = new WebsiteData;
data->setDataValues(name, url);
if (this->head == NULL) {
head = data;
data->previous = NULL;
current = head;
tail = head;
} else {
current->next = data;
data->previous = current;
//prev = current;
current = current->next;
tail = current;
}
}
void WebsiteList::addToTop(string name, string url) {
WebsiteData * data = new WebsiteData;
data->setDataValues(name, url);
if (this->head == NULL) {
head = data;
data->previous = NULL;
current = head;
tail = head;
} else {
WebsiteData * temp = head;
head = data;
head->previous = NULL;
head->next = temp;
temp->previous = head;
}
}
WebsiteData * WebsiteList::findData(string urlName) {
BrowserHistory list = BrowserHistory();
WebsiteData * temp = head;
for (int i = 0; i < list.size(); i++) {
string name = temp->name;
transform(name.begin(), name.end(), name.begin(), ::tolower);
if (name == urlName) {
return temp;
}
temp = temp->next;
}
return NULL;
}
WebsiteData * WebsiteList::getHead() {
return head;
}
WebsiteData * WebsiteList::getTail() {
return tail;
}
void WebsiteList::deleteFirstElement() {
WebsiteData * temp;
if (head->next != NULL) {
temp = head->next;
head = NULL;
head = temp;
}
}
void WebsiteList::deleteLastElement() {
WebsiteData * temp;
if (tail->previous != NULL) {
temp = tail->previous;
tail = NULL;
tail = temp;
} else {
if (tail != NULL) {
tail = NULL;
head = NULL;
}
}
}
void WebsiteList::deleteAll() {
BrowserHistory list = BrowserHistory();
for (int i = 0; i < list.size(); i++) {
deleteLastElement();
}
}
void WebsiteList::printBackwards() {
BrowserHistory list = BrowserHistory();
WebsiteData * temp = tail;
for (int i = 0; i < list.size(); i++) {
cout<<temp->name + " " + temp->url<<endl;
temp = temp->previous;
}
}