Skip to content

Commit

Permalink
Change ll_insert to O(1)
Browse files Browse the repository at this point in the history
  • Loading branch information
uoo723 committed Jun 22, 2017
1 parent 9021570 commit 6164c31
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
2 changes: 1 addition & 1 deletion include/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ typedef struct node {
} node_t;

node_t *ll_create();
int ll_insert(node_t *, unsigned int, char[VALUESIZE]);
int ll_insert(node_t *, unsigned int, char *);
int ll_delete(node_t *, unsigned int);
node_t *ll_get(node_t *, unsigned int);

Expand Down
11 changes: 3 additions & 8 deletions src/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ node_t *ll_create() {
return head;
}

int ll_insert(node_t *head, unsigned int key, char value[VALUESIZE]) {
int ll_insert(node_t *head, unsigned int key, char *value) {
if (head == NULL) {
return -1;
}
Expand All @@ -36,13 +36,8 @@ int ll_insert(node_t *head, unsigned int key, char value[VALUESIZE]) {
node->key = key;
strcpy(node->value, value);

node_t *iter = head;

while (iter->next != NULL) {
iter = iter->next;
}

iter->next = node;
node->next = head->next;
head->next = node;

return 0;
}
Expand Down

0 comments on commit 6164c31

Please sign in to comment.