|
@@ -39,21 +39,20 @@ void * get_previous(void *ptr) {
|
|
}
|
|
}
|
|
|
|
|
|
void remove_block(void *block, void *starting_node) {
|
|
void remove_block(void *block, void *starting_node) {
|
|
|
|
+
|
|
void *current_node, *previous_node;
|
|
void *current_node, *previous_node;
|
|
|
|
|
|
- // If the block to be removed is the head of the list, then just point
|
|
|
|
- // the next block as head.
|
|
|
|
- if(current_node == starting_node) {
|
|
|
|
- starting_node = get_next(block);
|
|
|
|
- // Else traverse through the list until the memory block is found.
|
|
|
|
- } else {
|
|
|
|
- for(current_node = starting_node; current_node != NULL;
|
|
|
|
- current_node = get_next(current_node)) {
|
|
|
|
- if(current_node == block) {
|
|
|
|
|
|
+ for(current_node = starting_node; current_node != NULL;
|
|
|
|
+ current_node = get_next(current_node)) {
|
|
|
|
+ if(current_node == block) {
|
|
|
|
+ if(current_node == starting_node) {
|
|
|
|
+ starting_node = get_next(block);
|
|
|
|
+ } else {
|
|
set_next(previous_node, get_next(block));
|
|
set_next(previous_node, get_next(block));
|
|
}
|
|
}
|
|
- previous_node = current_node;
|
|
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
|
|
+ previous_node = current_node;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|