From cdd4451596811d77ec648bf6bdd2bad12c0c49a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rom=C3=A1n?= <43916038+MrDave1999@users.noreply.github.com> Date: Sat, 6 Jun 2020 13:54:30 -0500 Subject: [PATCH] Update foreach.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Se quitaron las condiciones innecesarias que tenĂ­an las funciones "getNext". --- src/foreach.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/foreach.c b/src/foreach.c index b8b2906..9ae345c 100644 --- a/src/foreach.c +++ b/src/foreach.c @@ -25,28 +25,24 @@ #include "lst/ArrayQueue.h" #include "lst/ArrayStack.h" -void* getElementDefaultAL(ArrayList* al) +void setDefaultAL(ArrayList* al) { al->i = 0; - return (al->count == 0) ? (NULL) : (al->pArray[al->i]); } -void* getElementDefaultLK(LinkedList* lk) +void setDefaultLK(LinkedList* lk) { lk->aux = lk->pBegin; - return (lk->count == 0) ? (NULL) : (lk->aux->object); } -void* getElementDefaultAQ(ArrayQueue* qe) +void setDefaultAQ(ArrayQueue* qe) { qe->i = qe->begin; - return qe->pArray[qe->i]; } -void* getElementDefaultAS(ArrayStack* as) +void setDefaultAS(ArrayStack* as) { as->i = as->top; - return as->pArray[as->i]; } boolean hasNextAL(ArrayList* al) @@ -69,23 +65,19 @@ boolean hasNextAS(ArrayStack* as) return as->i < as->max; } -void* getNextElementAL(ArrayList* al) +void* getNextAL(ArrayList* al) { - return (++al->i < al->count) ? (al->pArray[al->i]) : (NULL); + return al->pArray[al->i++]; } -void* getNextElementLK(LinkedList* lk) +void* getNextLK(LinkedList* lk) { + void* aux = lk->aux->object; lk->aux = lk->aux->next; - return (lk->aux != NULL) ? (lk->aux->object) : (NULL); + return aux; } -void* getNextElementAQ(ArrayQueue* qe) +void* getNextAQ(ArrayQueue* qe) { - return (++qe->i < qe->n) ? (qe->pArray[qe->i % qe->max]) : (NULL); -} - -void* getNextElementAS(ArrayStack* as) -{ - return (++as->i < as->max) ? (as->pArray[as->i]) : (NULL); + return qe->pArray[qe->i++ % qe->max]; }