-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solution | ex01-05, ex07-08 #59
Conversation
Now all values bigger or less than 0 are supported as a result of comparison, previously supported results were -1, 0, 1
assert(my_strcmp("AB", "AC") < 0); | ||
assert(my_strcmp("AB", "AA") > 0); | ||
assert(my_strcmp("AB", "AD") < 0); | ||
} | ||
|
||
void test_long() | ||
{ | ||
assert(my_strcmp("HELLO WORLD", "HELLA WORLD") > 0); | ||
assert(my_strcmp("HELLO WORLD", "HELL WORLD") == 1); | ||
assert(my_strcmp("HELLO WORLD", "HELL WORLD") > 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing tests is not allowed unless there is a bug.
courses/cunix/ex02/src/my_strcmp.c
Outdated
*/ | ||
|
||
|
||
int my_strcmp(char *str1, char *str2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
brackets style is not consistent with other files
{ | ||
// using malloc to allocate memory from the heap | ||
char *str = malloc(sizeof nmb * CHAR_BIT + 1 + 1); | ||
sprintf(str, "%d", nmb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weeeeeell, it does not count :D
courses/cunix/ex07/src/linked_list.c
Outdated
typedef struct node { | ||
void *data; | ||
struct node *next; | ||
} node_t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be in header file
courses/cunix/ex07/src/linked_list.c
Outdated
} node_t; | ||
|
||
// Special internal function for node creation | ||
void *_node_create(void *data, node_t *next) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it creates a node it should return a node, not a void*
courses/cunix/ex07/src/linked_list.c
Outdated
} | ||
|
||
// Removes and returns node being pointed by 'ptr' | ||
void *list_remove(node_t **head, node_t *ptr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void *list_remove(node_t **head, int pos);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#61 Fixes the ambiguity of readme proposing one prototype, linked_list.h proposes another.
(*fp)(curr->data); | ||
curr = curr->next; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
functions removing nodes do not handle free nodes, solutions contains memory leaks
courses/cunix/ex08/src/binary_tree.c
Outdated
#include <string.h> | ||
#include <stdio.h> | ||
|
||
typedef struct node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type definition should be in header
courses/cunix/ex08/src/binary_tree.c
Outdated
} | ||
|
||
visit_tree(node->left, fp); | ||
(*fp)(node); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fp(node)
courses/cunix/ex08/src/binary_tree.c
Outdated
|
||
destroy_tree(node->left, fdestroy); | ||
destroy_tree(node->right, fdestroy); | ||
(*fdestroy)(node); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fdestroy(node)
Solutions to Week 2 tasks proposed by Nikita Sazonov