-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkedlist.h
58 lines (46 loc) · 1.28 KB
/
linkedlist.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
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include <QObject>
class Node : public QObject {
Q_OBJECT
Q_PROPERTY(int data READ getData WRITE setData NOTIFY dataChanged)
public:
Node(int data, Node* next = nullptr, QObject* parent = nullptr) : QObject(parent), m_data(data), m_next(next) {}
int getData() const { return m_data; }
void setData(int data) {
if (m_data != data) {
m_data = data;
emit dataChanged();
}
}
Node* getNext() const { return m_next; }
void setNext(Node* next) { m_next = next; }
signals:
void dataChanged();
private:
int m_data;
Node* m_next;
};
class LinkedList : public QObject {
Q_OBJECT
Q_PROPERTY(int score READ getScore WRITE setScore NOTIFY scoreChanged)
public:
LinkedList(QObject* parent = nullptr) : QObject(parent), m_head(nullptr), m_score(0) {}
Q_INVOKABLE void append(int data);
Q_INVOKABLE int calculateTotalScore() const;
void updateScore(int points);
void clear();
int getScore() const { return m_score; }
void setScore(int score) {
if (m_score != score) {
m_score = score;
emit scoreChanged();
}
}
signals:
void scoreChanged();
private:
Node* m_head;
int m_score;
};
#endif // LINKEDLIST_H