diff --git a/src/linkedlist.c b/src/linkedlist.c new file mode 100644 index 0000000000000000000000000000000000000000..b85c0d23ab2967baad1465c73755e0de05ded3d6 --- /dev/null +++ b/src/linkedlist.c @@ -0,0 +1,36 @@ +// +// by Boris Stefanovic on 31/05/22 +// + +#include "linkedlist.h" + + +ll_vint_node_t* ll_vint_create_node(const vector_int_t* vec) { + ll_vint_node_t* node = malloc(sizeof(ll_vint_node_t)); + if (NULL == node) return NULL; + node->data = vec; + node->next = NULL; +} + + +ll_vint_t* ll_vint_create() { + ll_vint_t* ll = NULL; + ll = malloc(sizeof(ll_vint_t)); + if (NULL == ll) return NULL; + ll->head = NULL; + ll->tail = NULL; + return ll; +} + + +void ll_vint_append(ll_vint_t* list, const vector_int_t* vector) { + if (NULL == vector) return; + ll_vint_node_t* node = ll_vint_create_node(vector); + if (NULL == list->head) { + list->head = node; + list->tail = list->head; + list->head->next = NULL; + } else { + // TODO + } +} diff --git a/src/linkedlist.h b/src/linkedlist.h new file mode 100644 index 0000000000000000000000000000000000000000..4141617368d6932cd8702da323e13532734a9842 --- /dev/null +++ b/src/linkedlist.h @@ -0,0 +1,29 @@ +// +// by Boris Stefanovic on 31/05/22 +// + +#ifndef PROG_KMEANS_LINKEDLIST_H +#define PROG_KMEANS_LINKEDLIST_H + +#include "vector.h" + + +typedef struct ll_vector_int_node { + const vector_int_t* data; + struct ll_vector_int_node* next; +} ll_vint_node_t; + +typedef struct ll_vector_int { + ll_vint_node_t* head; + ll_vint_node_t* tail; + size_t size; +} ll_vint_t; + +ll_vint_node_t* ll_vint_create_node(const vector_int_t* vec); + +ll_vint_t* ll_vint_create(); + +void ll_vint_append(ll_vint_t* list, const vector_int_t* vector); + + +#endif //PROG_KMEANS_LINKEDLIST_H diff --git a/src/main.c b/src/main.c index b1cb8d16f4eb2e2b57b686380c788051271ffaa6..aa0ddfdc49e27e0a33067bf30942e3fe1a2b25da 100644 --- a/src/main.c +++ b/src/main.c @@ -6,6 +6,7 @@ #include <string.h> #include <unistd.h> #include "common.h" +#include "linkedlist.h" #include "vector.h" void help(const char* callname) { @@ -50,6 +51,20 @@ vector_int_t* line_to_vector_int(char* line, const size_t dim) { } +ll_vint_t* get_vector_list(FILE* ifile, const size_t dim) { + ll_vint_t* list = ll_vint_create(); + char* line = NULL; + size_t len = 0; + while (getline(&line, &len, ifile) != -1) { + if (len != 0) { + vector_int_t* vector = line_to_vector_int(line, dim); + //TODO + free(line); + } + } +} + + int main(int argc, char** argv) { if (argc <= 1) help(argv[0]); char* ipath = NULL; @@ -77,9 +92,11 @@ int main(int argc, char** argv) { char* line = NULL; size_t len = 0; while (getline(&line, &len, ifile) != -1) { - vector_int_t* vector = line_to_vector_int(line, dim); - //TODO - free(line); + if (len != 0) { + vector_int_t* vector = line_to_vector_int(line, dim); + //TODO + free(line); + } } // WRITE FILE* ofile = opath != NULL ? fopen(opath, "w") : stdout;