// file: ll_remove_0.cc
//

// isip include files
//
#include "link_list.h"
#include "link_list_constants.h"

// method: remove_cc
//
// arguments:
//  Link_node* node : (input) a link node to remove from the list
//
// return: a logical_1 to indicate success
//
// this method removes the specified node from the linked list
//
logical_1 Link_list::remove_cc(Link_node* node_a) {

  // exit ungracefully if the node is null
  //
  if (node_a == (Link_node*)NULL) {
    return ISIP_FALSE;
  }

  // note the previous node of this node
  //
  Link_node* pnode = node_a->get_prev_cc();
  
  // if the head pointer is to be removed reset the head pointer
  //
  if (head_d == node_a) {
    head_d = head_d->get_next_cc();
    if (head_d != (Link_node*)NULL) {
      head_d->set_prev_cc(pnode);
    }
  }
  
  // otherwise remove the specified node from the list
  //
  else {
    head_d->remove_cc(node_a);
  }
  
  // adjust current pointer if necessary
  //
  if (curr_d == node_a) {
    curr_d = pnode;
  }
  
  // return the removed node to the free links pot in the memory manager
  //
  manager_d->delete_cc(node_a);
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
