123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #if 0
- struct node {
- char *uuid;
- char *data;
- struct node *next;
- };
- typedef struct node Node;
- #if 0
- void createq();
- int showfront(char *uuid, char *data);
- void addq(char *uuid, char *data);
- void delq();
- void showqueue();
- #endif
- Node *front, *rear;
- void createq() {
- printf("createq \n");
- front = rear = (Node*) malloc(sizeof(Node));
- front->next = rear->next = NULL;
- if(front == NULL)
- {
- printf("front is NULL \n");
- }
- else
- {
- printf("front is not NULL \n");
- }
- printf(" front: (@%p)\n",&(front->next));
- if(front->next == NULL)
- {
- printf("front->next is NULL \n");
- }
- else
- {
- printf("front->next is not NULL \n");
- }
- }
- int showfront(char *uuid, char *data){
- Node* tmpnode;
- front = rear = (Node*) malloc(sizeof(Node));
- front->next = rear->next = NULL;
- if(front->next == NULL)
- {
- printf("\n queue is null");
- strcpy(uuid,"");
- strcpy(data,"");
- return 0;
- }
- else
- {
- printf("test test 11111 !!! \n");
- printf("\n uuid:%s", front->next->uuid);
- printf("\n頂端值:%s", front->next->data);
- strcpy(uuid,front->next->uuid);
- strcpy(data,front->next->data);
- return 1;
- }
- }
- void addq(char *uuid, char *data) {
- Node *newnode;
- newnode = (Node*) malloc(sizeof(Node));
- if(front->next == NULL)
- front->next = newnode;
-
- newnode->uuid = uuid;
- newnode->data = data;
- newnode->next = NULL;
- rear->next = newnode;
- rear = newnode;
- }
- void delq() {
- Node* tmpnode;
- if(front->next == NULL) {
- printf("\n佇列已空!");
- return;
- }
- tmpnode = front->next;
- front->next = tmpnode->next;
- free(tmpnode);
- }
- void showqueue() {
- Node* tmpnode;
- tmpnode = front->next;
- printf("\n佇列內容:");
- while(tmpnode != NULL) {
- printf("%s ", tmpnode->data);
- tmpnode = tmpnode->next;
- }
- }
- #endif
|