listen.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. //type dfinitions
  5. typedef struct lin_list
  6. {
  7. char *value;
  8. struct lin_list *next;
  9. }LinListCell, *LinList_p;
  10. //function derfinitions
  11. LinList_p LinListAllocCell(char* value);
  12. void LinListFreeCell(LinList_p junk);
  13. void LinListFree(LinList_p *junk);
  14. LinList_p LinListInsertFirst(LinList_p anchor,LinList_p newCell);
  15. LinList_p LinListExtractFirst(LinList_p *anchor);
  16. LinList_p LinListFind(LinList_p anchor, char* value);
  17. int main(void)
  18. {
  19. LinList_p anchor = LinListAllocCell("xx");
  20. anchor->next = LinListAllocCell("xc");
  21. printf("anchor=%p\n",anchor);
  22. printf("%p %p \n", anchor->value,anchor->next->value);
  23. }
  24. LinList_p LinListFind(LinList_p anchor, char* value)
  25. {
  26. LinList_p cell = anchor;
  27. while(cell != NULL)
  28. {
  29. if(strcmp(value, cell->value)!=0)
  30. {
  31. return NULL;
  32. }else
  33. {
  34. return cell;
  35. }
  36. cell = cell->next;
  37. }
  38. }
  39. LinList_p LinListExtractFirst(LinList_p *anchor)
  40. {
  41. LinList_p buff = anchor;
  42. *anchor = anchor->next
  43. return buff;
  44. }
  45. LinList_p LinListInsertFirst(LinList_p anchor,LinList_p newCell)
  46. {
  47. LinListCell *buff = anchor;
  48. anchor = LinListAllocCell("");
  49. anchor->next = buff;
  50. }
  51. LinList_p LinListAllocCell(char* value)
  52. {
  53. LinList_p newcell = malloc(sizeof(LinListCell));
  54. newcell->next = NULL;
  55. newcell->value = strdup(value);
  56. return newcell;
  57. }
  58. void LinListFreeCell(LinList_p junk)
  59. {
  60. free(junk);
  61. }
  62. void LinListFree(LinList_p *junk)
  63. {
  64. LinListCell *next = junk;
  65. LinListCell *buff;
  66. *junk = NULL;
  67. while(next != NULL)
  68. {
  69. buff = next->next;
  70. free(next);
  71. }
  72. }