[ create a new paste ] login | about

Link: http://codepad.org/wRssci0L    [ raw code | output | fork ]

C, pasted on Apr 13:
struct cell{
  struct cell *next;
  int value;
};

void *append(struct cell *p, struct cell *q)
{
  while (p->next)
    p = p->next;
  p->next = q;
}

int main(void){
  struct cell pbuf[3];
  struct cell qbuf[2];
  struct cell *ret = pbuf;

  pbuf[0].value = 10;
  pbuf[0].next  = &pbuf[1];
  pbuf[1].value = 20;
  pbuf[1].next  = &pbuf[2];
  pbuf[2].value = 30;
  pbuf[2].next  = NULL;
  qbuf[0].value = 40;
  qbuf[0].next  = &qbuf[1];
  qbuf[1].value = 50;
  qbuf[1].next  = NULL;

  append(pbuf, qbuf);

  while (1) {
    printf("%d\n", ret->value);
    if (ret->next)
      ret = ret->next;
    else {
      break;
    }
  }


  return 0;
}


Output:
1
2
3
4
5
10
20
30
40
50


Create a new paste based on this one


Comments: