Commit 642ad524 authored by Chris's avatar Chris
Browse files

implemented a small linked list library; this will be used to cache store the fibonacci sequence

parent 4dfc099a
Loading
Loading
Loading
Loading
+243 −0

File changed.

Preview size limit exceeded, changes collapsed.

+5 −1
Original line number Diff line number Diff line
@@ -3,4 +3,8 @@ project(fibonacci_step_search C)

set(CMAKE_C_STANDARD 11)

add_executable(fibonacci_step_search main.c)
add_executable(fibonacci_step_search main.c
        fibonacci_ops.c
        fibonacci_ops.h
        linked_list.c
        linked_list.h)

fibonacci_ops.c

0 → 100644
+9 −0
Original line number Diff line number Diff line
//
// Created by Chris on 9/12/25.
//

#include "fibonacci_ops.h"

// create a linked list to cache the fibonacci numbers

// create the ability to calculate next value on demand based on the current linked list
 No newline at end of file

fibonacci_ops.h

0 → 100644
+8 −0
Original line number Diff line number Diff line
//
// Created by Chris on 9/12/25.
//

#ifndef FIBONACCI_STEP_SEARCH_FIBONACCI_OPS_H
#define FIBONACCI_STEP_SEARCH_FIBONACCI_OPS_H

#endif //FIBONACCI_STEP_SEARCH_FIBONACCI_OPS_H
 No newline at end of file

linked_list.c

0 → 100644
+41 −0
Original line number Diff line number Diff line
#include <stdlib.h>
#include "linked_list.h"
//
// Created by Chris on 9/12/25.
//

linked_list_item *create_node(unsigned int value) {
    linked_list_item *node = malloc(sizeof(*node));
    if (node == NULL) {
        return NULL;
    }
    node->value = value;
    node->next = NULL;
    return node;
}

int push(linked_list_item **head, unsigned int value) {
    linked_list_item *new_node = create_node(value);
    if (new_node == NULL) {
        return -1;
    }
    if (*head == NULL) {
        *head = new_node;
        return 0;
    }
    linked_list_item *current = *head;
    while (current->next != NULL) {
        current = current->next;
    }
    current->next = new_node;
    return 0;
}

void delete_linked_list(linked_list_item **head) {
    linked_list_item *current = *head;
    while (current != NULL) {
        linked_list_item *next = current->next;
        free(current);
        current = next;
    }
}
 No newline at end of file
Loading