fork(25) download
  1. #include <stdio.h>
  2. #include <sys/queue.h>
  3.  
  4. struct foo {
  5. TAILQ_ENTRY(foo) tailq;
  6. int datum;
  7. };
  8.  
  9. struct foo foo (int val) {
  10. struct foo x = { { 0, 0 }, val };
  11. return x;
  12. }
  13.  
  14. TAILQ_HEAD(fooq, foo);
  15.  
  16. int main ()
  17. {
  18. struct fooq q;
  19. struct foo data[3] = { foo(3), foo(7), foo(1) };
  20. struct foo *p;
  21.  
  22. TAILQ_INIT(&q);
  23. TAILQ_INSERT_HEAD(&q, &data[0], tailq);
  24. TAILQ_INSERT_AFTER(&q, &data[0], &data[1], tailq);
  25. TAILQ_INSERT_TAIL(&q, &data[2], tailq);
  26.  
  27. TAILQ_FOREACH(p, &q, tailq) {
  28. printf(" %d", p->datum);
  29. }
  30. puts("");
  31.  
  32. TAILQ_FOREACH_REVERSE(p, &q, fooq, tailq) {
  33. printf(" %d", p->datum);
  34. }
  35. puts("");
  36.  
  37. while (!TAILQ_EMPTY(&q)) {
  38. p = TAILQ_FIRST(&q);
  39. TAILQ_REMOVE(&q, p, tailq);
  40. }
  41.  
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
 3 7 1
 1 7 3