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 name="ChangeListManager">
<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$/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.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$/cmake-build-debug/Testing/Temporary/LastTest.log" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/Testing/Temporary/LastTest.log" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/main.cpp" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -64,31 +62,31 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"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"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;ModuleVcsDetector.initialDetectionPerformed&quot;: &quot;true&quot;,
&quot;RunOnceActivity.RadMigrateCodeStyle&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.cidr.known.project.marker&quot;: &quot;true&quot;,
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
&quot;RunOnceActivity.readMode.enableVisualFormatting&quot;: &quot;true&quot;,
&quot;RunOnceActivity.west.config.association.type.startup.service&quot;: &quot;true&quot;,
&quot;cf.advertisement.text.overridden&quot;: &quot;true&quot;,
&quot;cf.first.check.clang-format&quot;: &quot;false&quot;,
&quot;cidr.known.project.marker&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
&quot;junie.onboarding.icon.badge.shown&quot;: &quot;true&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.sourceCode.C++&quot;,
&quot;to.speed.mode.migration.done&quot;: &quot;true&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}]]></component>
}</component>
<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">
<method v="2">
@@ -111,6 +109,8 @@
<updated>1760370577663</updated>
<workItem from="1760370578774" duration="118000" />
<workItem from="1760788441262" duration="11460000" />
<workItem from="1760967500921" duration="5495000" />
<workItem from="1761213959983" duration="3160000" />
</task>
<servers />
</component>

View File

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

View File

@@ -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" <<endl;
if (tail == head)
tail = newNode;
}
TMovieNode* TMovieList::NavigateToNode(int index)
TMovieNode* TMovieList::NavigateToNode(const int index) const
{
// Negativ index finnes ikke -> 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)
@@ -79,3 +79,17 @@ void TMovieList::Remove(int index)
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 "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);
};

View File

@@ -1,7 +1,32 @@
#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()
{
std::cout << "Hello, World!" << std::endl;
return 0;
}