-
Notifications
You must be signed in to change notification settings - Fork 1
/
List.cpp
82 lines (63 loc) · 1.9 KB
/
List.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
#include "List.hpp"
#include <fstream>
#include <iostream>
// TODO: implement this function - Check
Employment* build_empl_list(std::string filename) {
Employment* head;
Employment* current;
std::ifstream file(filename);
if(!file){
return nullptr;
} else {
std::string ignoreMe;
file >> ignoreMe >> ignoreMe >> ignoreMe >> ignoreMe;
std::string area_fips;
unsigned long annual_avg_estabs, annual_avg_emplvl, total_annual_wages;
// Initialize first part
file >> area_fips >> annual_avg_estabs >> annual_avg_emplvl >> total_annual_wages;
current = new Employment(area_fips, annual_avg_estabs, annual_avg_emplvl, total_annual_wages);
// Save the head of the list
head = current;
while(file >> area_fips >> annual_avg_estabs >> annual_avg_emplvl >> total_annual_wages){
current->next = new Employment(area_fips, annual_avg_estabs, annual_avg_emplvl, total_annual_wages);
current = current->next;
}
current = nullptr;
return head;
}
}
// TODO: implement this function - Clear
void print_every_empl(Employment *emp) {
while(emp != nullptr){
std::cout << *emp << std::endl;
emp = emp->next;
}
}
// TODO: implement this function
int list_length(Employment *emp) {
int count = 0;
while(emp != nullptr){
count++;
emp = emp->next;
}
return count;
}
// TODO: implement this function
void append_lists(Employment* head, Employment* tail) {
auto cool = head;
while(cool->next != nullptr){
cool = cool->next;
}
cool->next = tail;
tail = nullptr;
}
void cleanup_list(Employment* list){
auto cool = list->next;
auto prev = list;
while(cool != NULL){
delete prev;
prev = cool;
cool = cool->next;
}
delete prev;
}