1. #include <stdio.h> 
  2. #include <stdlib.h> 
  3. typedef struct _queue 
  4.     int data; 
  5.     struct _queue *next; 
  6. }QUEUE; 
  7.  
  8. QUEUE *front = NULL, *rear = NULL; 
  9.  
  10. int InQueue(int value) 
  11.     QUEUE *temp = NULL; 
  12.      
  13.     temp = (QUEUE *)malloc(sizeof(QUEUE)); 
  14.     temp->data = value; 
  15.     temp->next = NULL; 
  16.  
  17.     if(front == NULL)    
  18.         front = temp; 
  19.     else  
  20.         rear->next = temp; 
  21.     rear = temp; 
  22.     return 1; 
  23. }                                //在队列 尾部 进行输入 
  24. int InQueue2(int value) 
  25.     QUEUE *temp = NULL; 
  26.     temp = (QUEUE *)malloc(sizeof(QUEUE)); 
  27.      
  28.     temp->data = value; 
  29.     temp->next =  NULL; 
  30.  
  31.     if(front == NULL && rear == NULL) 
  32.     { 
  33.         front = rear = temp; 
  34.         rear->next = front->next =  NULL; 
  35.     } 
  36.     else 
  37.     { 
  38.         temp->next = front; 
  39.         front = temp; 
  40.     } 
  41. }                        //在对列 头部进行输入 
  42.  
  43. int OutQueueByFront(int *value) 
  44.     QUEUE *temp = NULL; 
  45.     temp = front; 
  46.     if(front == NULL) 
  47.         return 0; 
  48.     *value = front->data; 
  49.     front = front->next; 
  50.     free(temp); 
  51.     return 1; 
  52.  
  53. int OutQueueByRear(int *value) 
  54.     QUEUE *temp; 
  55.     if(rear == NULL) 
  56.         return 0; 
  57.      
  58.     if(front == rear) 
  59.     { 
  60.         *value = rear->data; 
  61.         free(rear); 
  62.         front = NULL; 
  63.         rear = NULL; 
  64.     }else  
  65.     { 
  66.         temp = front; 
  67.         while(temp->next != rear) 
  68.             temp = temp->next; 
  69.         *value = rear->data; 
  70.         free(rear); 
  71.         rear = temp; 
  72.         rear->next = NULL; 
  73.     } 
  74.     return 1; 
  75.  
  76.  
  77. void main() 
  78.     int arr[6] = {1,2,3,4,5,6},res,i; 
  79.     for(i=0; i<6; i++) 
  80.         InQueue2(arr[i]); 
  81.     if(OutQueueByFront(&res)) 
  82.         printf("what we get is  %d  \n",res); 
  83.     else printf("we not get it\n"); 
  84.         if(OutQueueByRear(&res)) 
  85.         printf("what we get is  %d  \n",res); 
  86.     else printf("we not get it\n");