chore: use vector instead of custom linked list

This commit is contained in:
2026-03-27 16:52:52 +01:00
parent 90e5112afa
commit a43c055410
4 changed files with 10 additions and 28 deletions
-16
View File
@@ -1,16 +0,0 @@
#include "linked-list.hpp"
template <typename T> int insertNode(LinkedList<T> *list, T data) {
LinkedList<T> *node = new LinkedList<T>;
node->data = data;
if (list == nullptr) {
node->next = list;
list = node;
} else {
list->next = node;
}
return 0;
}
-8
View File
@@ -1,8 +0,0 @@
template <typename T>
struct LinkedList {
T data;
struct LinkedList* next;
};
template<typename T>
int insertNode(LinkedList<T> *, T);
+8 -2
View File
@@ -2,6 +2,7 @@
#include <iostream>
#include <regex>
#include <string>
#include <vector>
#include "parser.hpp"
#include "utils.hpp"
@@ -10,7 +11,7 @@ int process(std::string source) {
std::ifstream ifs(source);
std::string line;
LinkedList<Command> *commands = nullptr;
std::vector<Command> 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;
+2 -2
View File
@@ -1,6 +1,6 @@
#include <string>
#include <vector>
#include "linked-list.hpp"
#include "types.hpp"
int parseCommand(LinkedList<Command> *, std::string);
int parseCommand(std::vector<Command>&, std::string);