Skip to content
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

Closed
wants to merge 23 commits into from
Closed

Conversation

nksazonov
Copy link
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

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.

*/


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

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

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 on lines 22 to 25
typedef struct node {
void *data;
struct node *next;
} node_t;
Copy link

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

} node_t;

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

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*

}

// Removes and returns node being pointed by 'ptr'
void *list_remove(node_t **head, node_t *ptr)
Copy link

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

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

#include <string.h>
#include <stdio.h>

typedef struct node
Copy link

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

}

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

Choose a reason for hiding this comment

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

fp(node)


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

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