int main(int argc, char const *argv[]) {
      node * head=createnodes(10);
      printf("原链表\n");
      printnodes(head);
      insertnode(head,4,100);
      printf("插入2后链表\n");
      printnodes(head);
      deletenode(head,2);
      printf("删除1后链表\n");
      printnodes(head);
      //反序输出
      printnodesf(head);
      freenodes(head);
      return 0;
}
示例#2
0
/*
*  building optimum dichotomy tree on Burkov,Burkova's works
*/
node_t* optimal_dichotomic_tree ( const task_t *task){

  //{ finding q <= countItems - number of elements on which the maximal symmetric hierarchy must be created
    int q = find_q (task->b);
    q = (q > task->length) ? task->length : q;
  //}

  // maximum symmetric hierarchy must be created from top to down!
  // optimally sorting items
  item_t *diitems, // items for dichotomic part
         *dpitems; // items for dynamic programming branch
  prep_items(task->length, task->items, q, &diitems, &dpitems);

  // head of optimal dichotomic tree
  node_t* head = createnodes (2*task->length-1); // number of all nodes of any tree is doubled number of it's leafs minus one.
  head->hnode = NULL; // parentof the head of the tree

  // DP branch
  node_t *p = head;
  item_t *pl = dpitems, *tmp;
  int i;
  for ( i = 0 ; i < task->length-q ; i++ ) { // in fact p move as p = p + 2
    p->lnode = (p+1);
    p->lnode->items = NULL;
    tmp = copyitem(pl);
    HASH_ADD_KEYPTR ( hh, p->lnode->items, tmp->w, KNINT_SIZE, tmp);
    pl++;
    p->lnode->length = 1;
    p->lnode->hnode = p;
    
    p->rnode = (p+2);
    p->rnode->hnode = p;

    p = p->rnode;
  }

  // Dichotomic branch
  dicho_tree(p, q, diitems);

  return head;
}