TransactionQueue.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #if 0
  5. struct node {
  6. char *uuid;
  7. char *data;
  8. struct node *next;
  9. };
  10. typedef struct node Node;
  11. #if 0
  12. void createq();
  13. int showfront(char *uuid, char *data);
  14. void addq(char *uuid, char *data);
  15. void delq();
  16. void showqueue();
  17. #endif
  18. Node *front, *rear;
  19. void createq() {
  20. printf("createq \n");
  21. front = rear = (Node*) malloc(sizeof(Node));
  22. front->next = rear->next = NULL;
  23. if(front == NULL)
  24. {
  25. printf("front is NULL \n");
  26. }
  27. else
  28. {
  29. printf("front is not NULL \n");
  30. }
  31. printf(" front: (@%p)\n",&(front->next));
  32. if(front->next == NULL)
  33. {
  34. printf("front->next is NULL \n");
  35. }
  36. else
  37. {
  38. printf("front->next is not NULL \n");
  39. }
  40. }
  41. int showfront(char *uuid, char *data){
  42. Node* tmpnode;
  43. front = rear = (Node*) malloc(sizeof(Node));
  44. front->next = rear->next = NULL;
  45. if(front->next == NULL)
  46. {
  47. printf("\n queue is null");
  48. strcpy(uuid,"");
  49. strcpy(data,"");
  50. return 0;
  51. }
  52. else
  53. {
  54. printf("test test 11111 !!! \n");
  55. printf("\n uuid:%s", front->next->uuid);
  56. printf("\n頂端值:%s", front->next->data);
  57. strcpy(uuid,front->next->uuid);
  58. strcpy(data,front->next->data);
  59. return 1;
  60. }
  61. }
  62. void addq(char *uuid, char *data) {
  63. Node *newnode;
  64. newnode = (Node*) malloc(sizeof(Node));
  65. if(front->next == NULL)
  66. front->next = newnode;
  67. newnode->uuid = uuid;
  68. newnode->data = data;
  69. newnode->next = NULL;
  70. rear->next = newnode;
  71. rear = newnode;
  72. }
  73. void delq() {
  74. Node* tmpnode;
  75. if(front->next == NULL) {
  76. printf("\n佇列已空!");
  77. return;
  78. }
  79. tmpnode = front->next;
  80. front->next = tmpnode->next;
  81. free(tmpnode);
  82. }
  83. void showqueue() {
  84. Node* tmpnode;
  85. tmpnode = front->next;
  86. printf("\n佇列內容:");
  87. while(tmpnode != NULL) {
  88. printf("%s ", tmpnode->data);
  89. tmpnode = tmpnode->next;
  90. }
  91. }
  92. #endif