From 813811da43e7463a9f1b28f5da4d72380fdb9cb3 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 29 Aug 2022 13:35:52 +0200 Subject: [PATCH] Implementation poll --- .../src/testat_g11/SimplePriorityQueue.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/SimplePriorityQueue/src/testat_g11/SimplePriorityQueue.java b/SimplePriorityQueue/src/testat_g11/SimplePriorityQueue.java index 4969696..384bdf3 100644 --- a/SimplePriorityQueue/src/testat_g11/SimplePriorityQueue.java +++ b/SimplePriorityQueue/src/testat_g11/SimplePriorityQueue.java @@ -49,8 +49,22 @@ public class SimplePriorityQueue implements IPriorityQueue // Methode incrementAge() erhöht (Siehe Ticket im Paket testat_g11) @Override public T poll() { - // TODO Auto-generated method stub - return null; + if (size == 0) { + return null; + } + T tick = tickets[0]; + + for (int i = 1; i < size; i++) { + if (prioDet.calculate(tickets[i]) > prioDet.calculate(tick)) { + tick.incrementAge(); + tick = tickets[i]; + } else { + tickets[i].incrementAge(); + } + } + + remove(tick); + return tick; } // True: Ticket t ist enthalten, false sonst