From 3aecce5eaf77786d5fd73ba6ddaf01308259f765 Mon Sep 17 00:00:00 2001 From: Boris Stefanovic <owldev@bluewin.ch> Date: Tue, 31 May 2022 16:19:41 +0200 Subject: [PATCH] ADD: begin linked list; TODO: struct cluster, struct point(vector,cluster) --- src/linkedlist.c | 36 ++++++++++++++++++++++++++++++++++++ src/linkedlist.h | 29 +++++++++++++++++++++++++++++ src/main.c | 23 ++++++++++++++++++++--- 3 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 src/linkedlist.c create mode 100644 src/linkedlist.h diff --git a/src/linkedlist.c b/src/linkedlist.c new file mode 100644 index 0000000..b85c0d2 --- /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 0000000..4141617 --- /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 b1cb8d1..aa0ddfd 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; -- GitLab