1. #include <iostream> 
  2. using namespace std; 
  3.  
  4. struct Node 
  5.     int id; 
  6.     int childNum; 
  7.     Node* childList[10]; 
  8.      
  9. }; 
  10.  
  11. struct Queue 
  12.     Node* list[100]; 
  13.     int front; 
  14.     int rear; 
  15.     int num; 
  16. }; 
  17.  
  18. void InitQueue(Queue &q) 
  19.     q.front = q.rear = 99; 
  20.     q.num = 0; 
  21.  
  22. int EnQueue(Queue &q,Node* n) 
  23.     if (q.num == 100) return -1; 
  24.     q.rear = (q.rear+1)%100; 
  25.     q.list[q.rear] = n; 
  26.     q.num = q.num+1; 
  27.     return 1; 
  28.  
  29. int DeQueue(Queue &q,Node* &n) 
  30.     if (q.num == 0) return -1; 
  31.     q.front = (q.front+1)%100; 
  32.     n = q.list[q.front]; 
  33.     q.num = q.num-1; 
  34.     return 1; 
  35.  
  36.  
  37. int main() 
  38.     int i; 
  39.     Node* tree; 
  40.     tree = (Node*)malloc(sizeof(Node)); 
  41.     tree->id = 1; 
  42.     tree->childNum = 3; 
  43.     for (i=1;i<=tree->childNum;i++) 
  44.     { 
  45.         tree->childList[i-1] = (Node*)malloc(sizeof(Node)); 
  46.         tree->childList[i-1]->id = i+1; 
  47.         tree->childList[i-1]->childNum = 0; 
  48.     } 
  49.     tree->childList[0]->childNum = 2; 
  50.     tree->childList[0]->childList[0] = (Node*)malloc(sizeof(Node)); 
  51.     tree->childList[0]->childList[0]->id = 5; 
  52.     tree->childList[0]->childList[0]->childNum = 0; 
  53.     tree->childList[0]->childList[1] = (Node*)malloc(sizeof(Node)); 
  54.     tree->childList[0]->childList[1]->id = 6; 
  55.     tree->childList[0]->childList[1]->childNum = 0; 
  56.     Queue q; 
  57.     InitQueue(q); 
  58.     EnQueue(q,tree); 
  59.     while(q.num!=0) 
  60.     { 
  61.         Node* n; 
  62.         DeQueue(q,n); 
  63.         cout<<n->id<<' '
  64.         if (n->childNum!=0) 
  65.         { 
  66.             for (i=0;i<n->childNum;i++) EnQueue(q,n->childList[i]); 
  67.         } 
  68.     } 
  69.     cout<<endl; 
  70.     return 0; 

输出为:1 2 3 4 5 6