Esempio n. 1
0
tree_node *heap_insert(tree_node *head, int cust_num, int savings,
		       int node1, int node2)
{
  tree_node *temp;

  temp = make_heap(cust_num, savings, node1, node2);
  if (head == NULL)
     return(temp);

  head = merge_heaps(head, temp);

  return(head);
}
Esempio n. 2
0
tree_node *update_savings3(heur_prob *p, tree_node *head, tree_node *max_ptr,
			  _node *tour, route_data *route_info)
{
  tree_node *temp1, *temp2;
  int savings;
  int degree;
  tree_node *new_head;
  int node1, node2;

  if (head == NULL) return(NULL);

  temp1 = head->child;
  temp2 = head->sibling;
  savings = new_savings3(p, max_ptr, head, tour, &node1, &node2, route_info);
  if (savings == -MAXINT)
     return(NULL);
  new_head = make_heap(head->cust_num, savings, node1, node2);
  degree = head->degree;
  free(head);

  if (degree >0){
    temp1 = update_savings3(p, temp1, max_ptr, tour, route_info);
    if (!temp1)
       return(NULL);
    new_head = merge_heaps(temp1, new_head);
  }

  if (temp2!=NULL){
    temp2 = update_savings3(p, temp2, max_ptr, tour, route_info);
    if (!temp2)
       return(NULL);
    new_head = merge_heaps(temp2, new_head);
  }
  if(!degree && !temp2 &&!new_head) return(NULL);
  else return(new_head);
}
Esempio n. 3
0
tree_node *extract_max(tree_node *head, tree_node *max_ptr)
{
  tree_node *temp;

  temp = head;

  if (max_ptr == head)
    head = head->sibling;
  else{
    while(temp != NULL){
      if (temp->sibling == max_ptr){
	temp->sibling = temp->sibling->sibling;
	break;
      }
      temp=temp->sibling;
    }
  }
  if (max_ptr->child){
    temp = reverse_list(max_ptr->child);
    head = merge_heaps(temp, head);
  }
  return(head);
}