From 81d68a2807241848a9f96ae9f0f0b405f348154f Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 14 May 2020 16:39:49 +0200 Subject: fix: return node removed stack and queue --- I_anno/Programmazione_2/data_structures/stack.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'I_anno/Programmazione_2/data_structures/stack.cc') diff --git a/I_anno/Programmazione_2/data_structures/stack.cc b/I_anno/Programmazione_2/data_structures/stack.cc index 400039d..f1cc7d1 100644 --- a/I_anno/Programmazione_2/data_structures/stack.cc +++ b/I_anno/Programmazione_2/data_structures/stack.cc @@ -32,14 +32,14 @@ public: return this; } - stack* pop() { - if(!_head) return this; + node* pop() { + if(!_head) return nullptr; auto old_head = _head; + delete _head; _head = _head->next; - delete old_head; - return this; + return old_head; } void print() { @@ -59,7 +59,10 @@ int main() { s->pop(); s->push(4)->push(2)->push(8); - s->pop(); + s->print(); + auto e = s->pop(); + if(e) + cout << e->value << endl; s->push(1); s->print(); -- cgit v1.2.3-18-g5258