diff --git a/assignment1/.idea/workspace.xml b/assignment1/.idea/workspace.xml
index 53658aa..ba49448 100644
--- a/assignment1/.idea/workspace.xml
+++ b/assignment1/.idea/workspace.xml
@@ -30,13 +30,11 @@
-
-
-
+
@@ -64,31 +62,31 @@
- {
+ "keyToString": {
+ "ModuleVcsDetector.initialDetectionPerformed": "true",
+ "RunOnceActivity.RadMigrateCodeStyle": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "RunOnceActivity.cidr.known.project.marker": "true",
+ "RunOnceActivity.git.unshallow": "true",
+ "RunOnceActivity.readMode.enableVisualFormatting": "true",
+ "RunOnceActivity.west.config.association.type.startup.service": "true",
+ "cf.advertisement.text.overridden": "true",
+ "cf.first.check.clang-format": "false",
+ "cidr.known.project.marker": "true",
+ "git-widget-placeholder": "main",
+ "ignore.virus.scanning.warn.message": "true",
+ "junie.onboarding.icon.badge.shown": "true",
+ "node.js.detected.package.eslint": "true",
+ "node.js.detected.package.tslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.tslint": "(autodetect)",
+ "nodejs_package_manager_path": "npm",
+ "settings.editor.selected.configurable": "preferences.sourceCode.C++",
+ "to.speed.mode.migration.done": "true",
+ "vue.rearranger.settings.migration": "true"
}
-}]]>
+}
@@ -111,6 +109,8 @@
1760370577663
+
+
diff --git a/assignment1/TMovie.h b/assignment1/TMovie.h
index 0d611d6..c830548 100644
--- a/assignment1/TMovie.h
+++ b/assignment1/TMovie.h
@@ -2,8 +2,6 @@
#ifndef IKT203_TMOVIE_H
#define IKT203_TMOVIE_H
-
-
#include
#include
diff --git a/assignment1/TMovieList.cpp b/assignment1/TMovieList.cpp
index 5beb21b..4336c57 100644
--- a/assignment1/TMovieList.cpp
+++ b/assignment1/TMovieList.cpp
@@ -6,6 +6,7 @@ using namespace std;
void TMovieList::Append(TMovie* m)
{
+ // Time complexity O(1) with using tail and prev nodes
auto* newNode = new TMovieNode(m);
newNode->SetPrevNode(tail);
tail->SetNextNode(newNode);
@@ -24,13 +25,12 @@ void TMovieList::Prepend(TMovie* m)
if (old)
old->SetPrevNode(newNode);
-
cout << "Prepended '" << m->GetTitle() << "' into list of movies" < ugyldig
if (index < 0)
@@ -51,13 +51,13 @@ TMovieNode* TMovieList::NavigateToNode(int index)
}
-TMovie* TMovieList::GetAtIndex(int index)
+TMovie* TMovieList::GetAtIndex(const int index) const
{
auto* node = NavigateToNode(index);
return node ? node->GetMovie() : nullptr;
}
-void TMovieList::Remove(int index)
+void TMovieList::Remove(const int index)
{
auto* node = NavigateToNode(index);
if (node == nullptr)
@@ -78,4 +78,18 @@ void TMovieList::Remove(int index)
tail = head;
delete node;
-}
\ No newline at end of file
+}
+
+TMovie *TMovieList::SearchFor(const FCheckMovie check_movie, void *criteria) const
+{
+ auto* node = head->GetNextNode();
+ while (node != nullptr)
+ {
+ if (check_movie(node->GetMovie(), criteria))
+ {
+ return node->GetMovie();
+ }
+ node = node->GetNextNode();
+ }
+ return nullptr;
+}
diff --git a/assignment1/TMovieList.h b/assignment1/TMovieList.h
index 3a1df02..6d9e02a 100644
--- a/assignment1/TMovieList.h
+++ b/assignment1/TMovieList.h
@@ -4,6 +4,9 @@
#include "TMovie.h"
#include "TMovieNode.h"
+// typedef to increase flexibility and reduce code recycling
+typedef bool (*FCheckMovie)(TMovie* movie, void* criteria);
+
class TMovieList {
private:
TMovieNode* head;
@@ -26,10 +29,11 @@ public:
}
void Append(TMovie* m);
void Prepend(TMovie* m);
+ TMovie* SearchFor(FCheckMovie check_movie, void* criteria) const;
- TMovieNode *NavigateToNode(int index);
+ [[nodiscard]] TMovieNode *NavigateToNode(int index) const;
- TMovie* GetAtIndex(int index);
+ [[nodiscard]] TMovie* GetAtIndex(int index) const;
void Remove(int index);
};
diff --git a/assignment1/main.cpp b/assignment1/main.cpp
index 4f9de56..de37b87 100644
--- a/assignment1/main.cpp
+++ b/assignment1/main.cpp
@@ -1,7 +1,32 @@
#include
+#include "TMovieList.h"
+
+// specialised versions of SearchFor() from TMovieList
+bool SearchByTitle(const TMovie* m, void* c)
+{
+ const auto* title = static_cast(c);
+ return m->GetTitle() == *title;
+}
+
+bool SearchByDirector(const TMovie* m, void* criteria)
+{
+ const auto* director = static_cast(criteria);
+ return m->GetDirector() == *director;
+}
+
+bool SearchByGenre(const TMovie* m, void* criteria)
+{
+ const auto* genre = static_cast(criteria);
+ return m->GetGenre() == *genre;
+}
+
+
+
+
int main()
{
- std::cout << "Hello, World!" << std::endl;
- return 0;
+
+
+
}