// file: lat_wer_5.cc
//

// isip include files
//
#include "lattice.h"
#include "lattice_constants.h"

// method: free_list_cc
//
// arguments:
//  Link_list* list: (input) the link list to clean up
//
// return: a logical_1 indicating status
//
// this method deletes the contents of the input link list
//
logical_1 Lattice::free_list_cc(Link_list* list_a) {

  // memory manager
  //
  Memory_manager* manager = Link_list::get_manager_cc();
  
  // lattice path
  //
  Lattice_path* lpath = (Lattice_path*)NULL;

  // link nodes
  //
  Link_node* nd = (Link_node*)NULL;
  Link_node* pd = (Link_node*)NULL;
  
  // check if the link list exists
  //
  if (list_a != (Link_list*)NULL) {
    
    // loop over all nodes in the list
    //
    for (nd = list_a->get_head_cc(); nd != (Link_node*)NULL; nd = pd) {
      
      // get the next node
      //
      pd = nd->get_next_cc();
      
      // get the lattice path and delete it
      //
      lpath = (Lattice_path*)(nd->get_item_cc());
      manager->delete_cc(lpath);
      
      // delete this node
      //
      list_a->remove_cc(nd);
    }
  } // end if list exists
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
