-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelaxplan.h
150 lines (115 loc) · 4.08 KB
/
relaxplan.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
//
// RelaxPlan.h
// 2012PA1
//
// Created by TONY WAI SUM JI on 3/9/2019.
// Copyright © 2019 Tony Wai Sum JI. All rights reserved.
//
#ifndef RELAXPLAN_H
#define RELAXPLAN_H
#include <iostream>
#include <string>
#include "relaxation.h"
using namespace std;
/*-----------------------------
RelaxPlan Class (Linked list)
A buddy use relax plans to gain energy.
It manipulates a linked list of Relaxations, for exmaple:
RelaxPlan("Weekend!"):
Relaxation("Sleep", 10) next ->
Relaxation("Watch Movie with GF/BF/F/ALONE", 15) next ->
Relaxation("Sleep", 5) next ->
Relaxation("Play Switch with GF/BF/F/ALONE", 100) -> NULL
------------------------------*/
class RelaxPlan {
public:
/*-----------------------------
Constructor
@param name: string
@appendix: initialize head to NULL
------------------------------*/
RelaxPlan(string name);
/*-----------------------------
Copy Constructor
Copy name, and DEEP COPY the linked list: for every node (Relaxation*) in rp,
copy a new node of it, and link all copied nodes in the same sequence
------------------------------*/
RelaxPlan(RelaxPlan const & rp);
/*-----------------------------
Destructor
Deallocate all (Relaxation*) linked in this's linked list
------------------------------*/
~RelaxPlan();
/*-----------------------------
Head getter
@return: this's head
------------------------------*/
Relaxation* get_head() const;
/*-----------------------------
Append an relaxation to the START of the linked list,
@param r: a relaxation in STACK. You need to create a copy of it in HEAP, then do the append.
DON'T DIRECTLY USE &r to append.
Example:
initial: "Sleep for 1h" (head) -> "Play for 15 min" -> NULL
addToStart: "Complete 2012 PA1"
result: "Complete 2012 PA1" (head) -> "Sleep for 1h" -> "Play for 15 min" -> NULL
initial: NULL
addToEnd: "Complete 2012 PA1"
result: "Complete 2012 PA1" -> NULL
------------------------------*/
void addToStart(Relaxation r);
/*-----------------------------
Append an relaxation to the END of the linked list, for
@param r: a relaxation in STACK. You need to create a copy of it in HEAP, then do the append.
DON'T DIRECTLY USE &r to append.
Example:
initial: "Sleep for 1h" (head) -> "Play for 15 min" -> NULL
addToEnd: "Complete 2012 PA1"
result: "Sleep for 1h" (head) -> "Play for 15 min" -> "Complete 2012 PA1" -> NULL
initial: NULL
addToEnd: "Complete 2012 PA1"
result: "Complete 2012 PA1" -> NULL
------------------------------*/
void addToEnd(Relaxation r);
/*-----------------------------
Remove and deallocate a node at a given index
@ return: whether the removal is success or not
Example:
initial: "Sleep for 1h" (head) -> "Play for 15 min" -> "Complete 2012 PA1" -> NULL
remove: 3
result: false, nothing happened to the list
remove: 1
result: true, "Sleep for 1h" (head) -> "Complete 2012 PA1" -> NULL
remove: 1
result: true, "Sleep for 1h" (head) -> NULL
remove: 0
result: true, NULL (head)
remove: 0
result: false, nothing happened to the list
------------------------------*/
bool remove(int remove_index);
void print_details(int indent) const {
string out_indent = string(indent, '\t');
string in_indent = out_indent + "\t";
cout<<out_indent + "Relax Plan: "<<endl;
cout<<in_indent + "Name: "<<name<<endl;
if (head) {
cout<<in_indent + "Schedule: "<<endl;
Relaxation* curr = head;
int index = 0;
while (curr) {
curr->print_details(indent + 2, index, true);
curr = curr->get_next();
index++;
}
} else {
cout<<in_indent + "Schedule: NULL"<<endl;
}
}
private:
// Relax plan's name
string name;
// The pointer to the start of the relaxation linked list
Relaxation* head;
};
#endif /* RELAXPLAN_H */