Skip to content
Snippets Groups Projects
Commit 3aecce5e authored by Boris Stefanovic's avatar Boris Stefanovic
Browse files

ADD: begin linked list; TODO: struct cluster, struct point(vector,cluster)

parent d5d3eccc
Branches
No related tags found
No related merge requests found
//
// 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
}
}
//
// 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
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment