Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
TQueue
/** \file TQueue.c * \brief Implementace API pro typ fronta (realizace pomocí lineárního jednosměrně vázaného seznamu) * \author kolektivní vědomí ALD * \version 2021 * $Id: TQueue.c 1077 2021-02-19 14:35:22Z petyovsky $ */ /* VŠE NEJ K SVATKU <3 */ #include "TQueue.h" void queue_init(struct TQueue *aQueue) { if(aQueue) aQueue->iFront = aQueue->iBack = NULL; // Muze to byt i jako aQueue->iFront = !aQueue->iBack; ? } bool queue_is_empty(const struct TQueue *aQueue) { if(aQueue) //aQueue != NULL return (!aQueue->iFront); //aQueue->iFront == NULL return true; } bool /* TQueueIterator */ queue_front(const struct TQueue *aQueue, TQueueElement *aValue) { if (aQueue && aValue && aQueue->iFront) //mužu použit queue_is_empty? { *aValue = aQueue->iFront->iValue; return true; } return false; } bool /* TQueueIterator */ queue_back(const struct TQueue *aQueue, TQueueElement *aValue) { if(aQueue && aValue && aQueue->iBack) { *aValue = aQueue->iBack->iValue; return true; } return false; } bool queue_push(struct TQueue *aQueue, TQueueElement aValue) { if(aQueue) { struct TQueueNode* node = malloc(sizeof(struct TQueueNode)); if(!node) return false; *node = (struct TQueueNode) { .iValue = aValue, .iNext = NULL}; if(!aQueue->iFront) aQueue->iFront = node; else aQueue->iBack->iNext = node; aQueue->iBack = node; return true; } return false; } bool queue_pop(struct TQueue *aQueue) //xpetr { if(queue_is_empty(aQueue)) return false; struct TQueueNode* old_node = aQueue->iFront; aQueue->iFront = aQueue->iFront->iNext; free(old_node); if(!aQueue->iFront) aQueue->iBack = NULL; return false; } void queue_destroy(struct TQueue *aQueue) //xfranta { if(!aQueue) return; struct TQueueNode *tmp_node = aQueue->iFront; aQueue->iFront = aQueue->iBack = NULL; while (tmp_node) { struct TQueueNode *next = tmp_node->iNext; free(tmp_node); tmp_node = next; } } struct TQueueIterator queue_iterator_begin(const struct TQueue *aQueue) { if(queue_is_empty(aQueue)) return (struct TQueueIterator) { .iQueue = NULL, .iActual = NULL }; return (struct TQueueIterator) { .iQueue = aQueue, .iActual = aQueue->iFront }; } bool queue_iterator_is_valid(const struct TQueueIterator *aIter) { if(!aIter) return false; if (!aIter->iQueue || !aIter->iQueue->iFront || !aIter->iActual) return false; return true; } bool queue_iterator_to_next(struct TQueueIterator *aIter) { if (!queue_iterator_is_valid(aIter)) return false; aIter->iActual = aIter->iActual->iNext; return aIter->iActual != NULL; } TQueueElement queue_iterator_value(const struct TQueueIterator *aIter) { if (!queue_iterator_is_valid(aIter)) return (TQueueElement) { 0 }; return aIter->iActual->iValue; } bool queue_iterator_set_value(const struct TQueueIterator *aIter, TQueueElement aValue) { if (!queue_iterator_is_valid(aIter)) return false; aIter->iActual->iValue = aValue; return true; }
run
|
edit
|
history
|
help
0
TBod
Cross Platform Support for sprintf's Format '-Flag
BPC UDP cv10 cisla
discount sum
Square of a Number
BPC UDP pr2 cv10
crackme
pointery
TVector
Look at the bleeping warnings