Fix binstr_to_int loop bug. Add lf prefix
This commit is contained in:
parent
6737c3a781
commit
acf0164f4f
@ -6,12 +6,12 @@ set(CMAKE_C_STANDARD 99)
|
||||
include_directories(include)
|
||||
|
||||
set(SOURCES
|
||||
src/linkedlist.c
|
||||
src/set.c
|
||||
src/stack.c
|
||||
src/binarytree.c
|
||||
src/input.c
|
||||
src/math.c
|
||||
src/lflinkedlist.c
|
||||
src/lfset.c
|
||||
src/lfstack.c
|
||||
src/lfbinarytree.c
|
||||
src/lfinput.c
|
||||
src/lfmath.c
|
||||
)
|
||||
|
||||
add_library(flint ${SOURCES})
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef LIBFLINT_SET_H
|
||||
#define LIBFLINT_SET_H
|
||||
|
||||
#include "linkedlist.h"
|
||||
#include "lflinkedlist.h"
|
||||
|
||||
#define Set List
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef LIBFLINT_STACK_H
|
||||
#define LIBFLINT_STACK_H
|
||||
|
||||
#include "linkedlist.h"
|
||||
#include "lflinkedlist.h"
|
||||
|
||||
#define Stack List
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "binarytree.h"
|
||||
#include "lfbinarytree.h"
|
||||
|
||||
void bintree_init(BinTree *tree, void (*destroy)(void *data)) {
|
||||
tree->size = 0;
|
@ -7,7 +7,7 @@
|
||||
#include <bsd/stdlib.h>
|
||||
#endif
|
||||
|
||||
#include "input.h"
|
||||
#include "lfinput.h"
|
||||
|
||||
char *get_input(const char *path) {
|
||||
FILE *fp = NULL;
|
||||
@ -67,7 +67,7 @@ int *get_ints(const char *path, size_t *sz) {
|
||||
for (size_t idx = 0; idx < *sz; idx++) {
|
||||
int n;
|
||||
const char *errstr;
|
||||
n = strtonum(lines[idx], INT_MIN, INT_MAX, &errstr);
|
||||
n = (int)strtonum(lines[idx], INT_MIN, INT_MAX, &errstr);
|
||||
if (errstr) {
|
||||
printf("Failed to convert %s to int. Returning NULL\n", lines[idx]);
|
||||
exit(1);
|
@ -1,7 +1,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "linkedlist.h"
|
||||
#include "lflinkedlist.h"
|
||||
|
||||
void ll_init(List* list, void (*destroy)(void *data)) {
|
||||
list->size = 0;
|
@ -1,6 +1,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "math.h"
|
||||
#include "lfmath.h"
|
||||
|
||||
int max_int(int a, int b) {
|
||||
if (a > b) {
|
||||
@ -18,7 +18,7 @@ int min_int(int a, int b) {
|
||||
|
||||
int binstr_to_int(const char *s) {
|
||||
int n = 0, m = 1;
|
||||
for (size_t i = strlen(s) - 1; i >= 0; --i) {
|
||||
for (int i = (int)strlen(s) - 1; i >= 0; --i) {
|
||||
if (s[i] == '1') {
|
||||
n += m;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
#include "set.h"
|
||||
#include "lfset.h"
|
||||
|
||||
void set_init(Set* set, int (*match)(const void* a, const void* b),
|
||||
void (*destroy)(void* data)) {
|
@ -1,4 +1,4 @@
|
||||
#include "stack.h"
|
||||
#include "lfstack.h"
|
||||
|
||||
void stack_init(Stack* stack, void (*destroy)(void* data)) {
|
||||
ll_init(stack, destroy);
|
@ -1,10 +1,11 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "linkedlist.h"
|
||||
#include "set.h"
|
||||
#include "stack.h"
|
||||
#include "binarytree.h"
|
||||
#include "lflinkedlist.h"
|
||||
#include "lfset.h"
|
||||
#include "lfstack.h"
|
||||
#include "lfbinarytree.h"
|
||||
#include "lfmath.h"
|
||||
|
||||
void print_ll(List* list) {
|
||||
for (ListNode* node = list->head; node != NULL; node = node->next) {
|
||||
@ -146,10 +147,22 @@ void test_bintree() {
|
||||
bintree_destroy(tree);
|
||||
}
|
||||
|
||||
void test_math() {
|
||||
printf("\n--- MATH TEST ---\n");
|
||||
int i = 1, j = 2;
|
||||
printf("Between %d and %d, %d is larger\n", i, j, max_int(i, j));
|
||||
printf("Between %d and %d, %d is smaller\n", i, j, min_int(i, j));
|
||||
|
||||
char *s = "1010110";
|
||||
printf("Binary: %s\n", s);
|
||||
printf("Decimal: %d\n", binstr_to_int(s));
|
||||
}
|
||||
|
||||
int main() {
|
||||
test_ll();
|
||||
test_set();
|
||||
test_stack();
|
||||
test_bintree();
|
||||
test_math();
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user