-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItemTree.h
More file actions
62 lines (46 loc) · 1.38 KB
/
ItemTree.h
File metadata and controls
62 lines (46 loc) · 1.38 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
#ifndef ITEMTREE_H
#define ITEMTREE_H
#include <stdexcept>
#include <iostream>
#include <string>
#include "ShopItem.h"
class ItemTree {
private:
ShopItem* fKey; // Node's value (ShopItem)
ItemTree* fLeft; // Left child node
ItemTree* fRight; // Right child node
bool purchasable; // Flag to indicate if the item is purchasable
// Default private constructor (for sentinel node)
ItemTree();
public:
// Sentinel to represent an empty node
static ItemTree NIL;
// Constructor, initializes fKey and sets left/right to NIL
ItemTree(ShopItem* aKey);
// Check if the node is empty
bool isEmpty() const;
// Return the key, throws an exception if the node is empty
ShopItem* key() const;
// Access methods for left and right children
ItemTree* left();
ItemTree* right();
// Attach left child
void attachLeft(ItemTree* aTree);
// Attach right child
void attachRight(ItemTree* aTree);
// Detach left child
ItemTree* detachLeft();
// Detach right child
ItemTree* detachRight();
// Method to display the item tree
void display(int depth = 0) const;
// Check if the item is purchasable
bool isPurchasable() const;
// Set the item as purchasable
void setPurchasable(bool status);
// Mark children as purchasable
void unlockChildren();
// Destructor
~ItemTree();
};
#endif