Skip to content

Commit

Permalink
Merge pull request #21 from Garz4/main
Browse files Browse the repository at this point in the history
Fix thingies
  • Loading branch information
urielgarciarivas authored Dec 3, 2023
2 parents 4c8f003 + 09c1d5e commit 95f5e45
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
10 changes: 5 additions & 5 deletions DataStructures/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ test: hash_map_test hash_set_test linked_list_test sort_map_test sort_set_test
gcc -c $< -o $@

linked_list_test: test/linked_list_test.c $(OBJ)
$(CC) $(CFLAGS) test/linked_list_test.c -o linked_list_test $(OBJ)
$(CC) $(CFLAGS) $(INC) test/linked_list_test.c -o linked_list_test $(OBJ)

hash_map_test: test/hash_map_test.c $(OBJ)
$(CC) $(CFLAGS) test/hash_map_test.c -o hash_map_test $(OBJ)
$(CC) $(CFLAGS) $(INC) test/hash_map_test.c -o hash_map_test $(OBJ)

hash_set_test: test/hash_set_test.c $(OBJ)
$(CC) $(CFLAGS) test/hash_set_test.c -o hash_set_test $(OBJ)
$(CC) $(CFLAGS) $(INC) test/hash_set_test.c -o hash_set_test $(OBJ)

sort_map_test: test/sort_map_test.c $(OBJ)
$(CC) $(CFLAGS) test/sort_map_test.c -o sort_map_test $(OBJ)
$(CC) $(CFLAGS) $(INC) test/sort_map_test.c -o sort_map_test $(OBJ)

sort_set_test: test/sort_set_test.c $(OBJ)
$(CC) $(CFLAGS) test/sort_set_test.c -o sort_set_test $(OBJ)
$(CC) $(CFLAGS) $(INC) test/sort_set_test.c -o sort_set_test $(OBJ)

clean:
rm linked_list_test hash_map_test hash_set_test sort_map_test \
Expand Down
9 changes: 9 additions & 0 deletions DataStructures/src/linked_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ new_linked_list(int value) {

void
print_linked_list(const linked_list*const list) {
if (list == NULL) {
printf("list = {};\n");
return;
}

linked_list_node* head = list->head;
printf("list = {");

Expand All @@ -56,6 +61,10 @@ print_linked_list(const linked_list*const list) {

bool
exist_in_linked_list(const linked_list*const list, int value) {
if (list == NULL) {
return false;
}

linked_list_node* head = list->head;

while (head != NULL) {
Expand Down
15 changes: 13 additions & 2 deletions DataStructures/src/sort_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ new_sort_set(int value) {
inline void
add_to_sort_set(sort_set*const set, int value) {}

// Time: O(log(n))
// Space: O(1)
bool
exist_in_sort_set(const sort_set*const set, int target) {
if (set == NULL || set->size == 0) {
Expand All @@ -64,3 +62,16 @@ exist_in_sort_set(const sort_set*const set, int target) {

return false;
}

void
delete_sort_set(sort_set* set) {
if (set == NULL || set->root == NULL) {
return;
}

sort_set_node* node;
sort_set_node* left;
sort_set_node* right;

DEALLOCATE(set);
}
4 changes: 3 additions & 1 deletion DataStructures/src/sort_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ typedef struct __zng_ss_node {
struct __zng_ss_node* right;
} sort_set_node;

typedef struct ss {
typedef struct __zng_ss {
size_t size;
sort_set_node* root;
} sort_set;
Expand All @@ -46,4 +46,6 @@ extern void add_to_sort_set(sort_set*const set, int value);
// Space: O(1)
extern bool exist_in_sort_set(const sort_set*const set, int target);

extern void delete_sort_set(sort_set* list);

#endif // __ZNG_SORT_SET_H__
11 changes: 10 additions & 1 deletion DataStructures/test/sort_set_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@
int main(void) {
START_TEST("sort_set_test");

EXPECT_TRUE(1);
const size_t len = 15;
const int last_element = len - 1;
const int first_element = 0;
sort_set* set = new_sort_set(1);

for (int i = first_element + 1; i <= last_element; ++i) {
add_to_sort_set(set, i);
}

delete_sort_set(set);

FINISH_TEST();

Expand Down

0 comments on commit 95f5e45

Please sign in to comment.