From 563664931eb22e8ad11c6ff952c92c1853b1ccc5 Mon Sep 17 00:00:00 2001 From: Th3maz1ng Date: Sun, 8 Sep 2019 19:12:57 +0200 Subject: [PATCH] Updated Dictionary code --- src/software_test/tcpServer_test/Dictionary.h | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/software_test/tcpServer_test/Dictionary.h b/src/software_test/tcpServer_test/Dictionary.h index b9d2055..a5ffb9c 100644 --- a/src/software_test/tcpServer_test/Dictionary.h +++ b/src/software_test/tcpServer_test/Dictionary.h @@ -132,16 +132,16 @@ public: return remove(indiceToStr); } - boolean removeAt(unsigned int index) + boolean removeAt(unsigned int position) { - unsigned int position(0); + unsigned int pos(0); if(_head->_next == NULL) return false; Dictionary *cursor = _head, *toDelete(NULL); while(!isListEmpty(cursor->_next)) { - if(position++ == index) + if(pos++ == position) { toDelete = cursor->_next; cursor->_next = cursor->_next->_next; @@ -176,16 +176,32 @@ public: return get(parameter); } - T* get(const unsigned int index) + T* get(const unsigned int id) { - unsigned int position(0); + char indiceToStr[10]; + sprintf(indiceToStr,"%d", id); + + return get(indiceToStr); + } + + T* operator()(const unsigned int id) + { + char indiceToStr[10]; + sprintf(indiceToStr,"%d", id); + + return get(indiceToStr); + } + + T* getAt(const unsigned int position) + { + unsigned int pos(0); if(isListEmpty(_head->_next))return NULL; Dictionary *cursor = _head->_next; while(!isListEmpty(cursor)) { - if(position++ == index) + if(pos++ == position) return cursor->_value; cursor = cursor->_next; } @@ -193,11 +209,6 @@ public: return NULL; } - T* operator()(const unsigned int index) - { - return get(index); - } - unsigned int count() { unsigned int counter(0);