-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppsByIdTree.cpp
60 lines (43 loc) · 1.58 KB
/
AppsByIdTree.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
/****************************************************************************/
/* */
/* AppsByIdTree class implementation */
/* */
/****************************************************************************/
#include <cstdlib> // NULL definition
#include "AppsByIdTree.h"
#include "AVLTree.h"
#include "common.h"
void AppsByIdTree::addApp(const AppsListIterator& appData) {
// This function is basically an alias to AVLTree::insert()
// Use the appId as the search key
insert(appData->appId, appData);
}
void AppsByIdTree::removeApp(int appId) {
// This function is basically an alias to AVLTree::remove()
remove(appId);
}
AppsListIterator* AppsByIdTree::getAppById(int appId) const {
// This function is basically an alias to AVLTree::findBySearchKey()
return findBySearchKey(appId);
}
int AppsByIdTree::predKeyData(const int& key,
const AppsListIterator& data) const {
// Compare an appId with an AppData pointer:
// Simply compare the given appId with the appId in the structure
// pointed by data.
if (key < data->appId) {
return -1;
} else if (key > data->appId) {
return 1;
}
return 0;
}
int AppsByIdTree::predDataData(const AppsListIterator& data,
const AppsListIterator& other) const {
if (data->appId < other->appId) {
return -1;
} else if (data->appId > other->appId) {
return 1;
}
return 0;
}