sortlist.spc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. Module: Sort Linked Lists
  3. Author: [email protected] (Dick Grune @ Vrije Universiteit, Amsterdam)
  4. Version: Tue Sep 17 17:32:33 1991
  5. Description:
  6. This is the specification part of a generic routine that sorts linked
  7. lists. The elements in the list are structs, each of which carries a
  8. pointer to the next element.
  9. Instantiation, inline:
  10. For each struct list type T, specify:
  11. - a definition of SORT_STRUCT, the struct name of the linked
  12. structs
  13. - a definition of SORT_NAME, the name of the resulting sort
  14. routine
  15. - a definition of a routine
  16. int SORT_BEFORE(
  17. struct SORT_STRUCT *v, struct SORT_STRUCT *w
  18. )
  19. which yields non-zero if v is to be sorted before w
  20. - a definition of a field selector SORT_NEXT which names the
  21. field that points to the next struct SORT_STRUCT in the list
  22. - #include "sortlist.bdy"
  23. Instantiation, separate:
  24. For each struct list type T, create a file sortT.h which contains at
  25. least:
  26. - a definition of SORT_STRUCT, the struct name of the linked
  27. structs
  28. - a definition of SORT_NAME, the name of the resulting sort
  29. routine
  30. - #include "sortlist.spc"
  31. This file sortT.h is to be included in all files that use the routine
  32. SORT_NAME.
  33. For each struct list type T, create a file sortT.c which contains at
  34. least:
  35. - #include "sortT.h"
  36. - a definition of a routine
  37. int SORT_BEFORE(
  38. struct SORT_STRUCT *v, struct SORT_STRUCT *w
  39. )
  40. which yields non-zero if v is to be sorted before w
  41. - a definition of a field selector SORT_NEXT which names the
  42. field that points to the next struct SORT_STRUCT in the list
  43. - #include "sortlist.bdy"
  44. This file sortT.c compiles into the module object for SORT_STRUCT.
  45. Specification:
  46. The module supplies:
  47. - void SORT_NAME(struct SORT_STRUCT **listhook)
  48. where 'listhook' is a pointer to the location that holds the
  49. pointer to the list to be sorted. Upon return, the list will
  50. be sorted, and the pointer updated.
  51. The routine will be defined static when instantiated inline.
  52. Implementation:
  53. Linear insert sort:-(.
  54. */
  55. extern void SORT_NAME(struct SORT_STRUCT **);
  56. #define _SORT_EXTERN_DEFINED