Skip to content

Solution | ex01-05, ex07-08#59

Closed
nksazonov wants to merge 23 commits intoopenware:masterfrom
nksazonov:solution
Closed

Solution | ex01-05, ex07-08#59
nksazonov wants to merge 23 commits intoopenware:masterfrom
nksazonov:solution

Conversation

@nksazonov
Copy link
Copy Markdown
Contributor

Solutions to Week 2 tasks proposed by Nikita Sazonov

Comment on lines +13 to +21
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);
Copy link
Copy Markdown

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.

Comment thread courses/cunix/ex02/src/my_strcmp.c Outdated
*/


int my_strcmp(char *str1, char *str2) {
Copy link
Copy Markdown

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);
Copy link
Copy Markdown

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

Comment thread courses/cunix/ex07/src/linked_list.c Outdated
Comment on lines +22 to +25
typedef struct node {
void *data;
struct node *next;
} node_t;
Copy link
Copy Markdown

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

Comment thread courses/cunix/ex07/src/linked_list.c Outdated
} node_t;

// Special internal function for node creation
void *_node_create(void *data, node_t *next)
Copy link
Copy Markdown

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*

Comment thread 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)
Copy link
Copy Markdown

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);

Copy link
Copy Markdown
Contributor Author

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;
}
}
Copy link
Copy Markdown

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

Comment thread courses/cunix/ex08/src/binary_tree.c Outdated
#include <string.h>
#include <stdio.h>

typedef struct node
Copy link
Copy Markdown

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

Comment thread courses/cunix/ex08/src/binary_tree.c Outdated
}

visit_tree(node->left, fp);
(*fp)(node);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fp(node)

Comment thread courses/cunix/ex08/src/binary_tree.c Outdated

destroy_tree(node->left, fdestroy);
destroy_tree(node->right, fdestroy);
(*fdestroy)(node);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fdestroy(node)

@nksazonov nksazonov changed the title Solution | ex01-05, ex06-07 Solution | ex01-05, ex07-08 Aug 24, 2021
@josadcha josadcha closed this Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants