Exemple #1
0
/*
 * insert bid in descending cost
 */
void insert_bid(char *msg)
{
  char *p;
  Bid *b, *tb;
  int i, id;
  Dllist ptr;

  // create a new bid
  b = (Bid *) malloc(sizeof(Bid));
  p = strstr(msg, "B");
  p++;
  b->cost = atoi(p);
  p = strstr(p, "$");
  p++;
  b->numrobot = atoi(p);
  b->coalition = new_dllist();
  for (i = 0; i < b->numrobot; i++) {
    p = strstr(p, "$");
    p++;
    id = atoi(p);
    if (dll_empty(b->coalition)) b->leaderID = id;
    dll_append(b->coalition, new_jval_i(id)); 
  }

  printf("insert bid: %s\n", msg);
  // insert the bid to bidList, increasing cost
  if (dll_empty(bidList)) {
    dll_append(bidList, new_jval_v(b));
  } else {
    dll_traverse(ptr, bidList) {
      tb = (Bid *) jval_v(dll_val(ptr));
      if (tb->cost > b->cost) {
        dll_insert_b(ptr, new_jval_v(b));
        break;
      }
      if (ptr == dll_last(bidList)) {// append it to the last
        dll_append(bidList, new_jval_v(b));
        break;
      } 
    }
  }
Exemple #2
0
/** Inserts at the beginning of the list. */
void dll_prepend(Dllist l, Jval val)
{
  dll_insert_b(l->flink, val);
}
Exemple #3
0
/** Inserts at the end of the list. */
void dll_append(Dllist l, Jval val)
{
  dll_insert_b(l, val);
}
Exemple #4
0
/** Inserts after a given node. */
void dll_insert_a(Dllist n, Jval val)
{
  dll_insert_b(n->flink, val);
}
Exemple #5
0
void dll_prepend(Dllist l, Jval val)    /* Inserts at the beginning of the list */
{
  dll_insert_b(l->flink, val);
}
Exemple #6
0
void dll_append(Dllist l, Jval val)     /* Inserts at the end of the list */
{
  dll_insert_b(l, val);
}
Exemple #7
0
void dll_insert_a(Dllist n, Jval val)        /* Inserts after a given node */
{
  dll_insert_b(n->flink, val);
}