From 1e4762258f3e2d7db1045f3034e870f84cea7977 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 15 Apr 2022 09:44:49 +0300 Subject: Moved compare to DynStr --- .../Solutions Sem. 08/ex3/WordCollection.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/WordCollection.cpp') diff --git a/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/WordCollection.cpp b/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/WordCollection.cpp index 4a375e5..ff0b48b 100644 --- a/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/WordCollection.cpp +++ b/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/WordCollection.cpp @@ -30,10 +30,12 @@ void WordCollection::resize() { DynStr* newWords = new DynStr[length]; int* newSortMap = new int[length]; + for (int i = 0; i < oldLength; i++) { newWords[i] = words[i]; newSortMap[i] = sortMap[i]; } + delete[] words; delete[] sortMap; @@ -62,11 +64,7 @@ int WordCollection::findSortMapIndexWhen(int condition, const char* str) { // TODO: replace with binary search for (int i = 0; i < sortMapCount; i++) { - int cmp = strcmp(words[sortMap[i]].get_str(), str); - if (cmp > 1) cmp = 1; - else if (cmp < -1) cmp = -1; - - if (cmp == condition) + if (words[sortMap[i]].compare(str) == condition) return i; } return -1; -- cgit v1.3.1-23-gd82d