-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputList.cpp
More file actions
99 lines (93 loc) · 2.07 KB
/
InputList.cpp
File metadata and controls
99 lines (93 loc) · 2.07 KB
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
/*****************************************
- Quang Tran PSID: 1290921
- COSC 3360 Spring 2017
- Assignment 3 - PTHREAD program
*****************************************/
#include "InputList.h"
InputList::InputList()
{
empty = true;
top = NULL;
ptr = NULL;
}
InputList::~InputList()
{
}
InputList* InputList::setData(int numb, string lPlate, int aTime, int weight, int cTime)
{
data *newList = new data();
newList->numbList = numb;
newList->licensePlate = lPlate;
newList->arrvTime = aTime;
newList->loadWeight = weight;
newList->crossTime = cTime;
if (empty) { newList->prev = NULL, newList->next = NULL; top = newList; ptr = newList; empty = false; }
else
{
newList->prev = ptr;
newList->next = NULL;
ptr->next = newList;
ptr = newList;
}
return this;
}
data* InputList::getListData(InputList* inputList, int numb)
{
data *temp = inputList->top;
do{
if (temp->numbList == numb) return temp;
else{
if (temp->next != NULL) temp = temp->next;
else break;
}
} while (1);
return NULL;
}
string InputList::getLicensePlate(data *list)
{
return list->licensePlate;
}
int InputList::getArrivalTime(data *list)
{
return list->arrvTime;
}
int InputList::getLoadWeight(data *list)
{
return list->loadWeight;
}
int InputList::getCrossingTime(data *list)
{
return list->crossTime;
}
void InputList::clean(InputList* dataList)
{
do
{
data* temp = dataList->top;
if (temp->next != NULL)
{
temp->next->prev = NULL;
dataList->top = temp->next;
delete temp;
}
else
{
delete temp;
empty = true;
break;
}
} while (1);
}
string InputList::toString(InputList *dataList)
{
string toString;
data *temp = dataList->top;
do
{
dataList->ptr = temp;
toString += dataList->getLicensePlate(temp) + " " + to_string(dataList->getArrivalTime(temp)) + " " + to_string(dataList->getLoadWeight(temp)) + " " + to_string(dataList->getCrossingTime(temp)) + "\n";
if (temp->next != NULL) temp = dataList->ptr->next;
else break;
} while (1);
return toString;
}