diff options
Diffstat (limited to 'sem3/algo/mm2/linked/node.c')
-rw-r--r-- | sem3/algo/mm2/linked/node.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/sem3/algo/mm2/linked/node.c b/sem3/algo/mm2/linked/node.c index cce1be0..21f0993 100644 --- a/sem3/algo/mm2/linked/node.c +++ b/sem3/algo/mm2/linked/node.c @@ -4,10 +4,11 @@ #include <stdlib.h> /* Insert after node */ -node_t *node_insert(node_t *node, int val) { +node_t *node_insert(node_t *node, int val) +{ /* Create new node */ node_t *newNode = (node_t *) malloc( sizeof(node_t) ); - if( newNode == NULL ) { + if ( newNode == NULL ) { return NULL; } @@ -16,7 +17,7 @@ node_t *node_insert(node_t *node, int val) { newNode->prev = node; /* Check if there is node before */ - if( node == NULL ) { + if ( node == NULL ) { /* If not then there is no after */ newNode->next = NULL; return newNode; @@ -27,7 +28,7 @@ node_t *node_insert(node_t *node, int val) { node->next = newNode; /* Check node after */ - if( newNode->next != NULL ) { + if ( newNode->next != NULL ) { /* Backlink next node */ newNode->next->prev = newNode; } @@ -36,17 +37,18 @@ node_t *node_insert(node_t *node, int val) { } /* Pop node */ -int node_pop(node_t *node) { +int node_pop(node_t *node) +{ int val = node->val; /* Check prev */ - if( node->prev != NULL ) { + if ( node->prev != NULL ) { /* Point last node to next node */ node->prev->next = node->next; } /* Check next */ - if( node->next != NULL ) { + if ( node->next != NULL ) { node->next->prev = node->prev; } |