This commit is contained in:
Christopher Sanden
2025-10-23 16:20:45 +02:00
parent 266f5e5ff1
commit 8b0f75e5d8
5 changed files with 79 additions and 38 deletions

View File

@@ -30,13 +30,11 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="e3758ede-1321-4b2e-94dd-da87753a03f6" name="Changes" comment=""> <list default="true" id="e3758ede-1321-4b2e-94dd-da87753a03f6" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/editor.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/editor.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/TMovie.h" beforeDir="false" afterPath="$PROJECT_DIR$/TMovie.h" afterDir="false" /> <change beforePath="$PROJECT_DIR$/TMovie.h" beforeDir="false" afterPath="$PROJECT_DIR$/TMovie.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/TMovieList.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/TMovieList.cpp" afterDir="false" /> <change beforePath="$PROJECT_DIR$/TMovieList.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/TMovieList.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/TMovieList.h" beforeDir="false" afterPath="$PROJECT_DIR$/TMovieList.h" afterDir="false" /> <change beforePath="$PROJECT_DIR$/TMovieList.h" beforeDir="false" afterPath="$PROJECT_DIR$/TMovieList.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/TMovieNode.h" beforeDir="false" afterPath="$PROJECT_DIR$/TMovieNode.h" afterDir="false" /> <change beforePath="$PROJECT_DIR$/main.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/main.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmake-build-debug/Testing/Temporary/LastTest.log" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/Testing/Temporary/LastTest.log" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -64,31 +62,31 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"ModuleVcsDetector.initialDetectionPerformed": "true", &quot;ModuleVcsDetector.initialDetectionPerformed&quot;: &quot;true&quot;,
"RunOnceActivity.RadMigrateCodeStyle": "true", &quot;RunOnceActivity.RadMigrateCodeStyle&quot;: &quot;true&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.cidr.known.project.marker": "true", &quot;RunOnceActivity.cidr.known.project.marker&quot;: &quot;true&quot;,
"RunOnceActivity.git.unshallow": "true", &quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
"RunOnceActivity.readMode.enableVisualFormatting": "true", &quot;RunOnceActivity.readMode.enableVisualFormatting&quot;: &quot;true&quot;,
"RunOnceActivity.west.config.association.type.startup.service": "true", &quot;RunOnceActivity.west.config.association.type.startup.service&quot;: &quot;true&quot;,
"cf.advertisement.text.overridden": "true", &quot;cf.advertisement.text.overridden&quot;: &quot;true&quot;,
"cf.first.check.clang-format": "false", &quot;cf.first.check.clang-format&quot;: &quot;false&quot;,
"cidr.known.project.marker": "true", &quot;cidr.known.project.marker&quot;: &quot;true&quot;,
"git-widget-placeholder": "main", &quot;git-widget-placeholder&quot;: &quot;main&quot;,
"ignore.virus.scanning.warn.message": "true", &quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
"junie.onboarding.icon.badge.shown": "true", &quot;junie.onboarding.icon.badge.shown&quot;: &quot;true&quot;,
"node.js.detected.package.eslint": "true", &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
"node.js.detected.package.tslint": "true", &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
"node.js.selected.package.eslint": "(autodetect)", &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
"node.js.selected.package.tslint": "(autodetect)", &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
"nodejs_package_manager_path": "npm", &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
"settings.editor.selected.configurable": "preferences.sourceCode.C++", &quot;settings.editor.selected.configurable&quot;: &quot;preferences.sourceCode.C++&quot;,
"to.speed.mode.migration.done": "true", &quot;to.speed.mode.migration.done&quot;: &quot;true&quot;,
"vue.rearranger.settings.migration": "true" &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
} }
}]]></component> }</component>
<component name="RunManager" selected="C/C++ File.main.cpp"> <component name="RunManager" selected="C/C++ File.main.cpp">
<configuration name="assignment1" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="assignment1" TARGET_NAME="assignment1" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="assignment1" RUN_TARGET_NAME="assignment1"> <configuration name="assignment1" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="assignment1" TARGET_NAME="assignment1" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="assignment1" RUN_TARGET_NAME="assignment1">
<method v="2"> <method v="2">
@@ -111,6 +109,8 @@
<updated>1760370577663</updated> <updated>1760370577663</updated>
<workItem from="1760370578774" duration="118000" /> <workItem from="1760370578774" duration="118000" />
<workItem from="1760788441262" duration="11460000" /> <workItem from="1760788441262" duration="11460000" />
<workItem from="1760967500921" duration="5495000" />
<workItem from="1761213959983" duration="3160000" />
</task> </task>
<servers /> <servers />
</component> </component>

View File

@@ -2,8 +2,6 @@
#ifndef IKT203_TMOVIE_H #ifndef IKT203_TMOVIE_H
#define IKT203_TMOVIE_H #define IKT203_TMOVIE_H
#include <string> #include <string>
#include <utility> #include <utility>

View File

@@ -6,6 +6,7 @@ using namespace std;
void TMovieList::Append(TMovie* m) void TMovieList::Append(TMovie* m)
{ {
// Time complexity O(1) with using tail and prev nodes
auto* newNode = new TMovieNode(m); auto* newNode = new TMovieNode(m);
newNode->SetPrevNode(tail); newNode->SetPrevNode(tail);
tail->SetNextNode(newNode); tail->SetNextNode(newNode);
@@ -24,13 +25,12 @@ void TMovieList::Prepend(TMovie* m)
if (old) if (old)
old->SetPrevNode(newNode); old->SetPrevNode(newNode);
cout << "Prepended '" << m->GetTitle() << "' into list of movies" <<endl; cout << "Prepended '" << m->GetTitle() << "' into list of movies" <<endl;
if (tail == head) if (tail == head)
tail = newNode; tail = newNode;
} }
TMovieNode* TMovieList::NavigateToNode(int index) TMovieNode* TMovieList::NavigateToNode(const int index) const
{ {
// Negativ index finnes ikke -> ugyldig // Negativ index finnes ikke -> ugyldig
if (index < 0) 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); auto* node = NavigateToNode(index);
return node ? node->GetMovie() : nullptr; return node ? node->GetMovie() : nullptr;
} }
void TMovieList::Remove(int index) void TMovieList::Remove(const int index)
{ {
auto* node = NavigateToNode(index); auto* node = NavigateToNode(index);
if (node == nullptr) if (node == nullptr)
@@ -78,4 +78,18 @@ void TMovieList::Remove(int index)
tail = head; tail = head;
delete node; delete node;
} }
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;
}

View File

@@ -4,6 +4,9 @@
#include "TMovie.h" #include "TMovie.h"
#include "TMovieNode.h" #include "TMovieNode.h"
// typedef to increase flexibility and reduce code recycling
typedef bool (*FCheckMovie)(TMovie* movie, void* criteria);
class TMovieList { class TMovieList {
private: private:
TMovieNode* head; TMovieNode* head;
@@ -26,10 +29,11 @@ public:
} }
void Append(TMovie* m); void Append(TMovie* m);
void Prepend(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); void Remove(int index);
}; };

View File

@@ -1,7 +1,32 @@
#include <iostream> #include <iostream>
#include "TMovieList.h"
// specialised versions of SearchFor() from TMovieList
bool SearchByTitle(const TMovie* m, void* c)
{
const auto* title = static_cast<std::string*>(c);
return m->GetTitle() == *title;
}
bool SearchByDirector(const TMovie* m, void* criteria)
{
const auto* director = static_cast<std::string*>(criteria);
return m->GetDirector() == *director;
}
bool SearchByGenre(const TMovie* m, void* criteria)
{
const auto* genre = static_cast<EMovieGenreType*>(criteria);
return m->GetGenre() == *genre;
}
int main() int main()
{ {
std::cout << "Hello, World!" << std::endl;
return 0;
} }