File tree 2 files changed +13
-0
lines changed 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ class Node {
49
49
const std::string &getUserId () const ;
50
50
const T &getData () const ;
51
51
void setData (T &&new_data);
52
+
52
53
// operator
53
54
bool operator ==(const Node<T> &b) const ;
54
55
bool operator <(const Node<T> &b) const ;
Original file line number Diff line number Diff line change @@ -70,6 +70,18 @@ void Node<T>::setData(T &&new_data) {
70
70
this ->data = std::move (new_data);
71
71
}
72
72
73
+ bool deleteNodeById (const std::string &id) {
74
+ auto it = std::find_if (nodes.begin (), nodes.end (), [&](const auto &pair) {
75
+ return pair.second .getUserId () == id;
76
+ });
77
+
78
+ if (it != nodes.end ()) {
79
+ nodes.erase (it);
80
+ return true ; // Node deleted successfully
81
+ }
82
+ return false ; // Node not found
83
+ }
84
+
73
85
// The data type T must have an overload of the equality operator
74
86
template <typename T>
75
87
bool Node<T>::operator ==(const Node<T> &b) const {
You can’t perform that action at this time.
0 commit comments