From a43c0554103bde180033c9f46444077f7065d3aa Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Fri, 27 Mar 2026 16:52:52 +0100 Subject: [PATCH] chore: use vector instead of custom linked list --- src/linked-list.cpp | 16 ---------------- src/linked-list.hpp | 8 -------- src/main.cpp | 10 ++++++++-- src/parser.hpp | 4 ++-- 4 files changed, 10 insertions(+), 28 deletions(-) delete mode 100644 src/linked-list.cpp delete mode 100644 src/linked-list.hpp diff --git a/src/linked-list.cpp b/src/linked-list.cpp deleted file mode 100644 index d15a6ae..0000000 --- a/src/linked-list.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "linked-list.hpp" - -template int insertNode(LinkedList *list, T data) { - LinkedList *node = new LinkedList; - - node->data = data; - - if (list == nullptr) { - node->next = list; - list = node; - } else { - list->next = node; - } - - return 0; -} diff --git a/src/linked-list.hpp b/src/linked-list.hpp deleted file mode 100644 index 4586745..0000000 --- a/src/linked-list.hpp +++ /dev/null @@ -1,8 +0,0 @@ -template -struct LinkedList { - T data; - struct LinkedList* next; -}; - -template -int insertNode(LinkedList *, T); diff --git a/src/main.cpp b/src/main.cpp index ced9133..d26d71d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "parser.hpp" #include "utils.hpp" @@ -10,7 +11,7 @@ int process(std::string source) { std::ifstream ifs(source); std::string line; - LinkedList *commands = nullptr; + std::vector commands; while (getline(ifs, line)) { if (isComment(line) || isEmptyLine(line)) @@ -18,8 +19,13 @@ int process(std::string source) { int parseResult; - if ((parseResult = parseCommand(commands, line)) != 0) + if ((parseResult = parseCommand(commands, line)) != 0) { return parseResult; + } + } + + for (const Command &cmd : commands) { + std::cout << int(cmd.type) << " " << int(cmd.segment) << " " << cmd.index << std::endl; } return 0; diff --git a/src/parser.hpp b/src/parser.hpp index ab00850..b8ce4f5 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -1,6 +1,6 @@ #include +#include -#include "linked-list.hpp" #include "types.hpp" -int parseCommand(LinkedList *, std::string); +int parseCommand(std::vector&, std::string);