-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringlinkedlist.cpp
More file actions
41 lines (33 loc) · 872 Bytes
/
stringlinkedlist.cpp
File metadata and controls
41 lines (33 loc) · 872 Bytes
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
#include "stringlinkedlist.h"
#include <iostream>
using namespace std;
StringLinkedList::StringLinkedList() : head(NULL) { }
StringLinkedList:: ~StringLinkedList() { while (!empty()) removeFront(); }
bool StringLinkedList::empty() const {
return head == NULL;
}
const string& StringLinkedList::front() const {
return head->elem;
}
void StringLinkedList::addFront(const string& e) {
StringNode* v = new StringNode;
v->elem = e;
v->next = head;
head = v;
}
void StringLinkedList::removeFront() {
StringNode* old = head;
head = old->next;
delete old;
}
void StringLinkedList::display(ostream &out) const{
StringNode *curr = head;
while (curr != NULL) {
out << curr->elem << " ";
curr = curr->next;
}
}
ostream& operator<<(ostream &out, const StringLinkedList &L) {
L.display(out);
return out;
}