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/queue.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'I_anno/Programmazione_2/data_structures/queue.cc') diff --git a/I_anno/Programmazione_2/data_structures/queue.cc b/I_anno/Programmazione_2/data_structures/queue.cc index c565ac6..e1d4dcb 100644 --- a/I_anno/Programmazione_2/data_structures/queue.cc +++ b/I_anno/Programmazione_2/data_structures/queue.cc @@ -34,19 +34,21 @@ public: return this; } - queue* dequeue() { + node* dequeue() { auto iter = _head; - if(!_head) return this; + if(!_head) return nullptr; while(iter->next != _tail) { iter = iter->next; } + node* elem = iter->next; + delete iter->next; iter->next = nullptr; _tail = iter; - return this; + return elem; } void print() { @@ -67,7 +69,10 @@ int main() { q->dequeue(); q->enqueue(4)->enqueue(2)->enqueue(8); - q->dequeue(); + q->print(); + auto e = q->dequeue(); + if(e) + cout << e->value << endl; q->enqueue(1); q->print(); -- cgit v1.2.3-18-g5258