linkm.c 956 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. ** Written by David Gerdes US Army Construction Engineering Research Lab
  3. ** April 1992
  4. ** Copyright 1992 USA-CERL All rights reserved.
  5. **
  6. */
  7. /*
  8. ** takes 1st command line argument and stuffs each letter of it into
  9. ** a linked list. then prints it back out to stdout.
  10. ** If a second argument is specified, the first argument is put in the
  11. ** list backwards.
  12. */
  13. #include <stdio.h>
  14. #include <grass/linkm.h>
  15. struct link
  16. {
  17. char let;
  18. struct link *next;
  19. };
  20. int main(int argc, char *argv[])
  21. {
  22. register int i;
  23. VOID_T *head;
  24. struct link List, *tmp, *p;
  25. int rev = 0;
  26. /*
  27. List.next = NULL;
  28. List.let = ' ';
  29. */
  30. head = (VOID_T *) link_init(sizeof(struct link));
  31. for (i = 0; i < 2000000; i++) {
  32. /*
  33. p = (struct link *) malloc (sizeof (struct link));
  34. free (p);
  35. */
  36. p = (struct link *)link_new(head);
  37. link_destroy(head, p);
  38. }
  39. link_cleanup(head);
  40. exit(0);
  41. }