summaryrefslogtreecommitdiff
path: root/I_anno/Programmazione_2/data_structures/list_double.cc
diff options
context:
space:
mode:
Diffstat (limited to 'I_anno/Programmazione_2/data_structures/list_double.cc')
-rw-r--r--I_anno/Programmazione_2/data_structures/list_double.cc34
1 files changed, 19 insertions, 15 deletions
diff --git a/I_anno/Programmazione_2/data_structures/list_double.cc b/I_anno/Programmazione_2/data_structures/list_double.cc
index b229237..d8dda99 100644
--- a/I_anno/Programmazione_2/data_structures/list_double.cc
+++ b/I_anno/Programmazione_2/data_structures/list_double.cc
@@ -82,6 +82,24 @@ public:
return this;
}
+ list* pop(int val) {
+ if(_head == nullptr)
+ return this;
+ else if(_head->value == val)
+ return pop_front();
+
+ node<T>* iter = _head;
+ while(iter && iter->next && iter->next->value != val)
+ iter = iter->next;
+
+ node<T>* temp = iter->next;
+ iter->next = iter->next->next;
+ iter->next->prev = iter;
+ delete temp;
+
+ return this;
+ }
+
list* pop_front() {
if(_head == nullptr)
return this;
@@ -151,22 +169,8 @@ int main() {
l->print(); cout << endl;
l->pop_front();
l->print(); cout << endl;
- l->pop_back();
+ l->pop(2);
l->print(); cout << endl;
- // output
- /*
- * 1 [[ -1, 2 ]], 2 [[ 1, -1 ]],
- * 1 [[ -1, 2 ]], 2 [[ 1, 5 ]], 5 [[ 2, -1 ]],
- * 1 [[ -1, 2 ]], 2 [[ 1, 5 ]], 5 [[ 2, 10 ]], 10 [[ 5, 15 ]], 15 [[ 10, -1 ]],
- * 1 [[ -1, 2 ]], 2 [[ 1, 5 ]], 5 [[ 2, 6 ]], 6 [[ 5, 10 ]], 10 [[ 6, 15 ]], 15 [[ 10, -1 ]],
- * 1 [[ -1, 2 ]], 2 [[ 1, 5 ]], 5 [[ 2, 7 ]], 7 [[ 5, 6 ]], 6 [[ 7, 10 ]], 10 [[ 6, 15 ]], 15 [[ 10, -1 ]],
- * 1 [[ -1, 2 ]], 2 [[ 1, 4 ]], 4 [[ 2, 5 ]], 5 [[ 4, 7 ]], 7 [[ 5, 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