From 4f9b04c04920f90b4f5fd3504bff157141223722 Mon Sep 17 00:00:00 2001 From: DirtyDuckEUW Date: Mon, 18 Oct 2021 23:58:17 +0200 Subject: [PATCH] new file: LSList.h new file: LSListItem.h new file: LSMacros.h modified: LSString.h modified: LSString.vcxproj new file: LSVector.h modified: main.cpp --- LSString/LSList.h | 106 ++++++++++++++++++++++++++++++++++++++ LSString/LSListItem.h | 22 ++++++++ LSString/LSMacros.h | 15 ++++++ LSString/LSString.h | 16 +----- LSString/LSString.vcxproj | 4 ++ LSString/LSVector.h | 8 +++ LSString/main.cpp | 49 ++++++++++++++---- 7 files changed, 194 insertions(+), 26 deletions(-) create mode 100644 LSString/LSList.h create mode 100644 LSString/LSListItem.h create mode 100644 LSString/LSMacros.h create mode 100644 LSString/LSVector.h diff --git a/LSString/LSList.h b/LSString/LSList.h new file mode 100644 index 0000000..25eed2b --- /dev/null +++ b/LSString/LSList.h @@ -0,0 +1,106 @@ +#pragma once +#include "LSMacros.h" +#include "LSListItem.h" + +template + +class LSList +{ +public: + LSList() + { + } + + ~LSList() + { + DELETE_ARRAY(m_pFirst) + DELETE_ARRAY(m_pLast) + } + + LSListItem* Append(T tObj) + { + LSListItem* pNewLast; + if (!m_pFirst) + { + m_pFirst = new LSListItem(tObj); + m_pLast = new LSListItem(tObj); + m_pFirst->pNext = m_pLast; + pNewLast = m_pFirst; + } + else + { + pNewLast = new LSListItem(tObj); + if (m_pLast->pBefore) + { + LSListItem* pCurrentLast = m_pLast; + pCurrentLast->pNext = pNewLast; + pNewLast->pBefore = pCurrentLast; + } + else + { + m_pFirst->pNext = pNewLast; + pNewLast->pBefore = m_pFirst; + } + m_pLast = pNewLast; + } + m_zSize++; + return pNewLast; + } + + LSListItem* Remove(T tObj) + { + if (m_zSize == 0) return nullptr; + + LSListItem* pItemToRemove = m_pFirst; + + while (pItemToRemove->tValue != tObj) + { + pItemToRemove = pItemToRemove->pNext; + } + + LSListItem* pRet = nullptr; + + if (m_zSize <= 1) + { + m_pFirst = nullptr; + m_pLast = nullptr; + } + else if (pItemToRemove == m_pFirst) + { + LSListItem* pNewFirst = pItemToRemove->pNext; + pNewFirst->pBefore = nullptr; + m_pFirst = pNewFirst; + pRet = pNewFirst; + } + else if (pItemToRemove == m_pLast) + { + LSListItem* pNewLast = pItemToRemove->pBefore; + pNewLast->pNext = nullptr; + m_pLast = pNewLast; + pRet = pNewLast; + } + else + { + LSListItem* pBefore = pItemToRemove->pBefore; + LSListItem* pNext = pItemToRemove->pNext; + pBefore->pNext = pNext; + pNext->pBefore = pBefore; + pRet = pNext; + } + + DELETE_POINTER(pItemToRemove); + m_zSize--; + return pRet; + } + + T* RemoveAt(size_t zPos) + { + + } + +private: + LSListItem* m_pFirst = nullptr; + LSListItem* m_pLast = nullptr; + + size_t m_zSize = 0; +}; \ No newline at end of file diff --git a/LSString/LSListItem.h b/LSString/LSListItem.h new file mode 100644 index 0000000..0b55db7 --- /dev/null +++ b/LSString/LSListItem.h @@ -0,0 +1,22 @@ +#pragma once + +template + +class LSListItem +{ +public: + LSListItem(T tObj) + : tValue(tObj) + { + + } + + ~LSListItem() + { + + } + + LSListItem* pBefore = nullptr; + LSListItem* pNext = nullptr; + T tValue; +}; \ No newline at end of file diff --git a/LSString/LSMacros.h b/LSString/LSMacros.h new file mode 100644 index 0000000..ce607ec --- /dev/null +++ b/LSString/LSMacros.h @@ -0,0 +1,15 @@ +#pragma once + +#define DELETE_POINTER(Pointer) \ +if (Pointer != nullptr)\ +{\ + delete Pointer;\ + Pointer = nullptr;\ +} + +#define DELETE_ARRAY(Array) \ +if (Array != nullptr)\ +{\ + delete[] Array;\ + Array = nullptr;\ +} \ No newline at end of file diff --git a/LSString/LSString.h b/LSString/LSString.h index 8617564..ab26f9b 100644 --- a/LSString/LSString.h +++ b/LSString/LSString.h @@ -1,23 +1,9 @@ #pragma once #include +#include "LSMacros.h" class LSString { -private: -#define DELETE_POINTER(Pointer) \ -if (Pointer != nullptr)\ -{\ - delete Pointer;\ - Pointer = nullptr;\ -} - -#define DELETE_ARRAY(Array) \ -if (Array != nullptr)\ -{\ - delete[] Array;\ - Array = nullptr;\ -} - public: // - Constructor LSString() = default; diff --git a/LSString/LSString.vcxproj b/LSString/LSString.vcxproj index d70572a..db6de7f 100644 --- a/LSString/LSString.vcxproj +++ b/LSString/LSString.vcxproj @@ -157,7 +157,11 @@ + + + + diff --git a/LSString/LSVector.h b/LSString/LSVector.h new file mode 100644 index 0000000..ab8b150 --- /dev/null +++ b/LSString/LSVector.h @@ -0,0 +1,8 @@ +#pragma once + +template + +class LSVector +{ +}; + diff --git a/LSString/main.cpp b/LSString/main.cpp index 761998c..6d0b308 100644 --- a/LSString/main.cpp +++ b/LSString/main.cpp @@ -1,5 +1,6 @@ #include #include "LSString.h" +#include "LSList.h" #include "Timer.h" #define RUNS 50U @@ -7,20 +8,46 @@ int main() { - printf("LSString:\n"); - printf("Number of runs: %d:\n", (int)RUNS); - Timer ttt; - for (size_t zRun = 1; zRun <= RUNS; zRun++) + // - STRING { - printf("Run: %2d: ", (int)zRun); - - Timer tt; - LSString s("361"); - - for (size_t z = 0; z < RUNS * 187; z++) + printf("LSString:\n"); + printf("Number of runs: %d:\n", (int)RUNS); + Timer ttt; + for (size_t zRun = 1; zRun <= RUNS; zRun++) { - s.Append(PAYLOAD); + printf("Run: %2d: ", (int)zRun); + + Timer tt; + LSString s("361"); + + for (size_t z = 0; z < RUNS * 187; z++) + { + s.Append(PAYLOAD); + } } } + + // - LIST + { + int i1 = 1187; + int i2 = 2361; + int i3 = 3257; + int i4 = 41337; + int i5 = 569; + + LSList liList; + auto a1 = liList.Append(i1); + auto a2 = liList.Append(i2); + auto a3 = liList.Append(i3); + auto a4 = liList.Append(i4); + auto a5 = liList.Append(i5); + + liList.Remove(i1); + liList.Remove(i5); + liList.Remove(i3); + liList.Remove(i4); + liList.Remove(i2); + liList.Remove(i1); + } return 0; } \ No newline at end of file