Exemplo n.º 1
0
int main(int argc, char* argv[])
{
    bool ok;

    Queue queue;
    queue.EnQueue(1);
    queue.EnQueue(2);
    queue.EnQueue(3);


    // queue.ClearQueue();
    // queue.IsEmpty();


    while (!queue.IsEmpty())
    {
        cout << queue.DeQueue(ok) << endl;
    }

    queue.EnQueue(5);
    queue.EnQueue(6);

    while (!queue.IsEmpty())
    {
        cout << queue.DeQueue(ok) << endl;
    }

    return 0;
}
Exemplo n.º 2
0
bool Spread::ModelSpread(Queue<long> &lqueue,map<long,UserStatus> &userSMap)
{
    map<long,UserStatus>::iterator iter2;
    map<long,float> userSMapDcache;
    map<long,float>::iterator iter3;
    map<long int,UserLink>::iterator iter4;
    while(!lqueue.IsEmpty()){
            long userid = lqueue.GetQueue();
            iter4 = userGraphMap->find(userid);
            //免疫因子 /mu
            if(userSMap[userid].tfIdf<mu){
                      continue;
            }
            if(iter4 != userGraphMap->end())
            {
                UserLink head = iter4->second;
                float srcWeight = head->weight;
                float dstWeight;
                int connect;
                UserNode *g = head->next;
                while(g!=NULL){
                    iter2 = userSMap.find(g->uid);
                    if(iter2 == userSMap.end())
                    {
                        dstWeight = g->weight;
                        connect = g->connect;
                        float diffuseRate = DiffuseRate(srcWeight,dstWeight,connect);
                        float tfIdf = userSMap[userid].tfIdf;
                        iter3 = userSMapDcache.find(g->uid);
                        if(iter3 != userSMapDcache.end())
                            userSMapDcache[g->uid] += tfIdf*diffuseRate;
                        userSMapDcache[g->uid] = tfIdf*diffuseRate;
                    }
                    g = g->next;
                }
            }
            if(lqueue.IsEmpty())
            {
               for(iter3 = userSMapDcache.begin();iter3 != userSMapDcache.end();iter3++)
               {
                   lqueue.EnQueue(iter3->first);
                   UserStatus userStatus;
                   userStatus.infected =true;
                   userStatus.tfIdf = iter3->second;
                   userSMap[iter3->first] = userStatus;
               }
               userSMapDcache.clear();
            }
        }
    return true;
}
Exemplo n.º 3
0
void  menuQueue()
{
	Queue *queue = new Queue;
	char c;
	do
	{
		printf("1: Push\n");
		printf("2: Pop\n");
		printf("3: IsEmpty\n");
		printf("\nEsc: Exit\n");
		c = getch();
		switch(c)
		{
		case '1': 
			cout << "Push:";
			int val;
			cin >> val;
			queue->Push(val);
			cout << endl; break;
		case '2': 
			cout << "Pop:";
			int v;
			v = queue->Pop();
			cout << v << endl; break;
		case '3': 
			cout << "IsEmpty:";
			bool flag = queue->IsEmpty();
			cout << ( flag == true ? "true" : "false") << endl; break;
		}
	} while(c != 27);
	delete queue;
}
Exemplo n.º 4
0
int main()
{
    Queue<int> queue;
    queue.Enqueue(10);
    queue.Enqueue(20);
    cout<<queue.IsEmpty()<<endl;
    cout<<queue.IsFull()<<endl;
    cout<<queue.Front()<<endl;
    queue.Dequeue();
    cout<<queue.Front()<<endl;
    return 0;
}
Exemplo n.º 5
0
Arquivo: 8.cpp Projeto: 3588/au-cs230
void Airport::Run(){ 
	int pri;
	airplane p;
	for(nowtime=1;nowtime<=endtime;nowtime++){
		cout<<"\nThe "<<nowtime<<" Minutes";
		pri=PRand(expectland);
		for(int i=1;i<=pri;i++){
			p=*Newairplane(p,ARRIVE);
		if(airland.IsFull())NoServe(p,ARRIVE);else {airland.Add(p);if(1!=airland.Size())cout<<" waiting on runway.";}
		}

		pri=PRand(expectfly);
		for(int i1=1;i1<=pri;i1++){
			p=*Newairplane(p,FLY);
 if(airfly.IsFull())NoServe(p,FLY);else {airfly.Add(p);if(1!=airland.Size()+airfly.Size())cout<<" waiting on runway.";}
		}

		if(airland.IsEmpty())Freeplane();
		if(!airland.IsEmpty()){p=*airland.Delete(p);Land(p,3);}
		else if(!airfly.IsEmpty()){p=*airfly.Delete(p);Fly(p,3);}
	}
	GetCalculate();
}
Exemplo n.º 6
0
int main(int argc, char** argv)
{
	// Stack test
	Stack<int> s;
	s.Push(10);
	s.Push(20);
	s.Push(30);
	s.Push(40);
	s.Push(1);
	s.Push(2);
	s.Push(3);
	s.Push(4);
	s.Push(5);
	s.Push(6);
	s.Push(7);
	s.Push(8);
	while(!s.IsEmpty())
	{
		printf("%d\n", s.Top());
		s.Pop();
	}
	printf("-----\n");
	
	// Queue test
	Queue<int> q;
	q.Enque(10);
	q.Enque(20);
	q.Enque(30);
	q.Enque(40);	
	q.Enque(1);
	q.Enque(2);
	q.Enque(3);
	q.Enque(4);
	q.Enque(5);
	q.Enque(6);
	q.Enque(7);
	q.Enque(8);
	while(!q.IsEmpty())
	{
		printf("%d\n", q.Front());
		q.Deque();
	}
	printf("-----\n");

	// Maze test
	path(argv[1]);
		
	return 0;
}
Exemplo n.º 7
0
template<typename T>void BinaryTree<T>::WidthOrder(TNode<T> *Current){
    if(Current!=NULL){
        Queue<TNode<T>*> q;      // 队列
        q.EnQue(Current);
        TNode<T> * p;
        while(!q.IsEmpty()) {
            p = q.DeQue();   // 队首元素出队列
            cout<<p->info<<'\t';	          // 访问p结点
            if(p->lchild)
                q.EnQue(p->lchild);
            if(p->rchild)
                q.EnQue(p->rchild);
        }  						//后序访问根结点
    }
}
Exemplo n.º 8
0
int main(int argc, const char * argv[]) {
    // insert code here...
   	int i;
    Queue<char> que;                             //缺省为18元素队列,可用17
    char str1[]="abcdefghijklmnop";//17个元素,包括串结束符
    que.MakeEmpty();
    for(i=0;i<17;i++) que.EnQue(str1[i]);
    if(que.IsFull()) cout<<"队满";
    cout<<"共有元素:"<<que.Length()<<endl;
    for(i=0;i<17;i++) cout<<que.DeQue();           //先进先出
    cout<<endl;
    if(que.IsEmpty()) cout<<"队空";
    cout<<"共有元素:"<<que.Length()<<endl;
    return 0;
}
Exemplo n.º 9
0
void Router::propagate(Coordinate *source, Coordinate *target){
  int stepId = 0;
  queue->Add(source);
  visit(source, stepId);
  Coordinate *current;
  GridPoint currentGridPoint;
  bool targetFound = false;

  do{
    //get the next node from queue
    current = queue->Remove();
    currentGridPoint = getGridPointAt(current);
    stepId = currentGridPoint.StepId + 1;
    //get neighbors of source
    Coordinate *neighbors = current->GetNeighbors();

    int i;
    //if any of them is the target, stop,
    for (i = 0; i < 4; i++) {
      if(neighbors[i].Equals(target)){
        visit(&neighbors[i], stepId);
        targetFound = true;
        break;
      }

      //add it to the queue if 
      //it is not out of bounds
      //it is not visited
      if(neighbors[i].InBound(rows, cols) && !isVisited(&neighbors[i])){
        queue->Add(&neighbors[i]);
        visit(&neighbors[i], stepId);
      }

    }
  }while(!queue->IsEmpty() && !targetFound);

  //else add them to the queue
  //do the same with the rest of the elements in the queue until the target is
  //reached

}
Exemplo n.º 10
0
int main(void){
    
    int N = 10;    

    // instantiate a Queue that stores integers
    //
    Queue<int> *q = new Queue<int>();
     
    for(int i=1; i < N; ++i)
        q->Enqueue(i); 
    q->PrintItems();
    if(q->IsEmpty()) cout << "Queue is empty\n";    

    // Access the front in the Queue
    //
    cout << "Front Item: " << q->Front() << endl;
    cout << "Removing Front Item\n";
    // Remove the front item in the Queue
    q->Dequeue();

    // Print the Items
    q->PrintItems();
    return 0;
}
Exemplo n.º 11
0
bool FindPath(Position start, Position finish,
             int& PathLen, Position * &path)
{// Find a path from start to finish.
 // Return true if successful, false if impossible.
 // Throw NoMem exception if inadequate space.

   if ((start.row == finish.row) &&
      (start.col == finish.col))
         {PathLen = 0; return true;} // start = finish

   // initialize wall of blocks around grid
   for (int i = 0; i <= m+1; i++) {
      grid[0][i] = grid[m+1][i] = 1; // bottom & top
      grid[i][0] = grid[i][m+1] = 1; // left & right
      }

   // initialize offsets
   Position offset[4];
   offset[0].row = 0; offset[0].col = 1; // right
   offset[1].row = 1; offset[1].col = 0; // down
   offset[2].row = 0; offset[2].col = -1; // left
   offset[3].row = -1; offset[3].col = 0; // up

   int NumOfNbrs = 4; // neighbors of a grid position
   Position here, nbr;
   here.row = start.row;
   here.col = start.col;
   grid[start.row][start.col] = 2; // block
   
   // label reachable grid positions
   Queue<Position> Q;
   do 
   {// label neighbors of here
      for (int i = 0; i < NumOfNbrs; i++) 
      {
         nbr.row = here.row + offset[i].row;
         nbr.col = here.col + offset[i].col;
         if (grid[nbr.row][nbr.col] == 0) 
         {
             // unlabeled nbr, label it
             grid[nbr.row][nbr.col] = grid[here.row][here.col] + 1;

             if ((nbr.row == finish.row) && (nbr.col == finish.col)) 
                 break; // done
             Q.Add(nbr);
         } // end of if
      } // end of for
      
      // have we reached finish?
      if ((nbr.row == finish.row) &&
          (nbr.col == finish.col)) break; // done

      // finish not reached, can we move to a nbr?
      if (Q.IsEmpty()) return false; // no path
      here = Q.First();// get next position
      Q.Delete(); 
   } while(true);
            
   // construct path
   PathLen = grid[finish.row][finish.col] - 2;
   path = new Position [PathLen];

   // trace backwards from finish
   here = finish;
   for (int j = PathLen-1; j >= 0; j--) {
      path[j] = here;
      // find predecessor position
      for (int i = 0; i < NumOfNbrs; i++) {
         nbr.row = here.row + offset[i].row;
         nbr.col = here.col + offset[i].col;
         if (grid[nbr.row][nbr.col] == j+2) break;
         }
      here = nbr;  // move to predecessor
      }

   return true;
}
Exemplo n.º 12
0
int main(void)
{
	int *data;														  // 用來接收一副牌的資料
    int times = 1,total = 0;										  
	int faceu[SIZE][7] = {0};										  // 7 plies of face-up cards

	Queue stockcards;											      // storage facedown stock cards
	Stack wastecards;									              // storage face-up waste plie cards
	Stack faced[7];												      // 7 piles of facedown cards
	int Spade, Heart, Diamond, Club;						          // output plies
	Number num[7] = {0};											  // record faceu's status

    while(times <= 100)
	{
		int i = 0, j = 0, k = 0, action = 0;						  // counter, action是動作計數器
		int counter = 0;											  // 判斷步驟用的變數
		int score = -52;											  // 分數
		Club = Diamond = Heart = Spade = 0;							  // output plies initial
        data = new_set_of_cards(times);								  // 要一副洗好的牌資料 , times為100次中的第幾次

		for(i = 1; i <= 28 ;)										  // 發牌到下面七個row裡
		{
			for(j = k; j < 7; j++ ,i++)
			{
				faced[j].Push(data[i-1]);
				num[j].fst = num[j].nth = (data[i-1] - 1) % 13;
				num[j].fstcardno = num[j].cardno = data[i-1];
			}
			k++;
		}

		for(i = 28 ; i < 52 ; i++)									  // 發剩下的牌到牌堆裡
		{
			stockcards.Add(data[i]);
		}

		for(i = 0 ; i < 7 ; i++)									  // 翻開playing plie最下面的牌
		{
			faceu[0][i] = faced[i].Pop();	
			num[i].sheets = 1;
		}

		wastecards.Push(stockcards.Delete());						  // 從牌堆翻一張牌到waste plie

		while(counter == 0)
		{
			counter = 1;			
//(a)從wasteplie和playing plie把最上方的牌移至output區                      ( counter = 1 )
//   如果wasteplie空了,就從牌堆翻開一張牌放到wasteplie	
/*-------------------------------------------------------------------------------------------------------*/		
			while(counter == 1)
			{	 /*----------wastecards part----------*/
				if((wastecards.Top() - 1) == (13 * 0) + Spade   ||(wastecards.Top() - 1) == (13 * 1) + Heart 
				 ||(wastecards.Top() - 1) == (13 * 2) + Diamond ||(wastecards.Top() - 1) == (13 * 3) + Club)
				{/*----------可以放上去的狀況---------*/
					score += 5;
					switch((wastecards.Top() - 1) / 13)
					{
						case 0:
							Spade++;
							break;
						case 1:
							Heart++;
							break;
						case 2:
							Diamond++;
							break;
						case 3:
							Club++;
							break;
					}
					wastecards.Pop();
					
					action++;
					if(wastecards.IsEmpty())
					{
						wastecards.Push(stockcards.Delete());
					}
					counter = 0;
					break;
				}	
				/*------playing plies part-------*/
				for(i = 0 ; i < 7 ; i++)
				{
					if((num[i].cardno - 1) == (13 * 0) + Spade   || (num[i].cardno - 1) == (13 * 1) + Heart 
				    || (num[i].cardno - 1) == (13 * 2) + Diamond || (num[i].cardno - 1) == (13 * 3) + Club)
					{/*-------可以放上去的狀況-------*/
						score += 5;
						switch((num[i].cardno - 1) / 13)
						{
							case 0:
								Spade++;
								break;
							case 1:
								Heart++;
								break;
							case 2:
								Diamond++;
								break;
							case 3:
								Club++;
								break;
						}
						num[i].sheets--;
						faceu[num[i].sheets][i] = 0;
						num[i].nth++;
						action++;

						if(num[i].sheets != 0) // faceu non-empty
						{
							num[i].cardno = faceu[num[i].sheets-1][i];
						}
						else // faceu empty
						{
							if(!faced[i].IsEmpty()) // faced non-empty
							{
								faceu[0][i] = faced[i].Pop();
								num[i].fstcardno = num[i].cardno = faceu[0][i];
								num[i].nth = num[i].fst = (faceu[0][i]-1) % 13;
								num[i].sheets = 1;
							}
							else// faced empty
							{
								num[i].sheets = num[i].fstcardno = num[i].cardno = num[i].nth = num[i].fst = 0;
							}
						}
						counter = 0;
						break;
					}
					else // have no action
					{
						counter = 2; // jump to step(b)
					}
				}	
			}
/*-------------------------------------------------------------------------------------------------------*/		
//(b)從wasteplie移動最上方的牌到playing plie,可以移動的話以最左邊為主             ( counter = 2 )
//   如果wasteplie空了,就從牌堆翻一張牌到wasteplie						
/*-------------------------------------------------------------------------------------------------------*/		
			while(counter == 2)
			{
				for(i = 0 ; i < 7 ; i++)
				{
					if(num[i].sheets != 0)  // faceu non-empty
					{
						if( (wastecards.Top() - 1) / 13 + (num[i].cardno - 1) / 13 != 3 && 
							(wastecards.Top() - 1) / 13 != (num[i].cardno- 1) / 13) // different color
						{
							if((wastecards.Top() - 1) % 13 == num[i].nth - 1) // point continue
							{
								num[i].nth--;
								num[i].cardno = wastecards.Pop();	
								faceu[num[i].sheets][i] = num[i].cardno;
								num[i].sheets++;
								action++;
	
								if(wastecards.IsEmpty())
								{		
									wastecards.Push(stockcards.Delete());
								}

								break;
							}
						}

					}
					else// faceu empty
					{
						if(wastecards.Top() % 13 == 0 && wastecards.Top() != 0) // K
						{
							num[i].fstcardno = num[i].cardno = faceu[num[i].sheets][i] = wastecards.Pop();	
							num[i].fst = num[i].nth = 12;
							num[i].sheets = 1;
							action++;

							if(wastecards.IsEmpty())
							{
								wastecards.Push(stockcards.Delete());
							}

						break;
						}
					}
				}
				if(action != 0)  // have action
				{
					counter = 0; // jump to step(a)
				}
				else // have no action
				{
					counter = 3; // jump to step(c)
				}
			}
/*-------------------------------------------------------------------------------------------------------*/		
/*(c)從最左邊找已經faceup的playing plie,是否可以移動至其他playing plie              ( counter = 3 )
   此移動為所有同一個playing plie下所有faceup的牌一起移動					*/
/*-------------------------------------------------------------------------------------------------------*/		
			while(counter == 3)
			{
				for(i = 0 ; i < 7 ; i++)
				{	
					if(action != 0)     // have action
					{
						break;			
					}
					for(j = 0 ; j < 7 ; j++)
					{							
						int k = 0;     // program counter		
						if(num[i].sheets != 0 && i != j)// faceu non empty (source)
						{
							if(num[j].sheets != 0)// faceu non empty (target)
							{
								if( (num[i].fstcardno - 1) / 13 + (num[j].cardno - 1) / 13 != 3 && 
									(num[i].fstcardno - 1) / 13 != (num[j].cardno - 1) / 13) // different color
								{									
									if(num[i].fst == num[j].nth - 1) // point continue
									{
										while(k < num[i].sheets)
										{
											num[j].cardno = faceu[num[j].sheets][j] = faceu[k][i];
											faceu[k][i] = 0;
											num[j].sheets++;
											num[j].nth = (num[j].cardno - 1) % 13;
											k++;
										}
										action++;
										num[i].sheets = num[i].fstcardno = num[i].cardno = num[i].nth = num[i].fst = 0; // null, after move

										if(!faced[i].IsEmpty())
										{
											faceu[0][i] = faced[i].Pop();
											num[i].fstcardno = num[i].cardno = faceu[0][i];
											num[i].nth = num[i].fst = (faceu[0][i]-1)%13;
											num[i].sheets = 1;
										}
									}
								}
							}
							else// faceu empty
							{
								if((num[i].fst) == 12 && !faced[i].IsEmpty()) // K
								{
									num[j].fst = num[j].nth = 12;
									num[j].fstcardno = num[i].fstcardno;

									while(k < num[i].sheets)
									{
										num[j].cardno = faceu[num[j].sheets][j] = faceu[k][i];
										faceu[k][i] = 0;
										num[j].sheets++;
										num[j].nth = (num[j].cardno - 1) % 13;
										k++;
									}
									action++;
									num[i].sheets = num[i].fstcardno = num[i].cardno = num[i].nth = num[i].fst = 0;

									if(!faced[i].IsEmpty())
									{
										faceu[0][i] = faced[i].Pop();
										num[i].fstcardno = num[i].cardno = faceu[0][i];
										num[i].nth = num[i].fst = (faceu[0][i]-1)%13;
										num[i].sheets = 1;
									}
								}
							}
						}

						if(action != 0)
						{
							break;			
						}

					}
				}

				if(action != 0)    // have action
				{
					counter = 0;   // jump to step (a)
				}
				else               // have no action
				{
					counter = 4;   // jump to step (e)
				}	
			}
/*-------------------------------------------------------------------------------------------------------*/		
//(e)如果(a).(b).(c)都不能移動的話,從牌堆翻開一張牌放到wasteplie,然後從(a)步驟重新判斷 ( counter = 4 )
/*-------------------------------------------------------------------------------------------------------*/		
			while(counter == 4)
			{
				if(!stockcards.IsEmpty())
				{
					wastecards.Push(stockcards.Delete());
				}
				counter = 0;					 // jump to step (a)
			}
/*-------------------------------------------------------------------------------------------------------*/			
			for(i = 0 ; i < 7 ; i++) // 檢查playing plie 裡面是不是還有可以放在output裡的牌, waste plie裡是否
			{						 // 可以放在playing plie裡以及playing plie 是否還可以移動, 若可移動則action++
				if((num[i].cardno - 1) == (13 * 0) + Spade   || (num[i].cardno - 1) == (13 * 1) + Heart 
				 ||(num[i].cardno - 1) == (13 * 2) + Diamond || (num[i].cardno - 1) == (13 * 3) + Club)
				{
					action++;
				}
				if( (wastecards.Top() - 1) / 13 + (num[i].cardno - 1) / 13 != 3 && 
				    (wastecards.Top() - 1) / 13 != (num[i].cardno- 1) / 13) // different color
				{
					if((wastecards.Top() - 1) % 13 == num[i].nth - 1) // point continue
					{
						action++;
					}
				}
				for(j = 0 ; j < 7 ; j++)
				{											
					if(num[i].sheets != 0 && i != j)// faceu non empty (source)
					{
						if(num[j].sheets != 0)// faceu non empty (target)
						{
							if( (num[i].fstcardno - 1) / 13 + (num[j].cardno - 1) / 13 != 3 && 
								(num[i].fstcardno - 1) / 13 != (num[j].cardno - 1) / 13) // different color
							{									
								if(num[i].fst == num[j].nth - 1) // point continue
								{
									action++;
								}
							}
						}
					
						else
						{
							if((num[i].fst) == 12 && !faced[i].IsEmpty()) // K
							{
								action++;
							}
						}
					}
				}
			}
			if((wastecards.Top() - 1) == (13 * 0) + Spade  || (wastecards.Top() - 1) == (13 * 1) + Heart 
			||(wastecards.Top() - 1) == (13 * 2) + Diamond || (wastecards.Top() - 1) == (13 * 3) + Club)
			{                                  // 檢查waste plie裡面是不是還有可以放在output裡的牌, 若有則action++
				action++;
			}

			if(stockcards.IsEmpty()	&& action == 0) // 牌堆沒牌以及所有牌不可再移動時結束遊戲
			{  
				break;
			}
			action = 0;

		}    //play finish

		total += score;
		printf("%3d times score = %3d\n", times, score); //print score and times
		printf("\n");
/*---------------------------清空資料動作---------------------------*/
		for(i = 0 ; i < 7 ; i++)
		{
			while(!faced[i].IsEmpty())
			{
				faced[i].Pop();
			}

			num[i].sheets = num[i].fstcardno = num[i].cardno = num[i].nth = num[i].fst = 0;

			for(j = 0 ; j < SIZE ; j++)
			{
				faceu[j][i] = 0;
			}
		}
		while(stockcards.IsEmpty() && wastecards.IsEmpty())
		{
			stockcards.Delete();
			wastecards.Pop();
		}
        free(data); // 釋放記憶體
        times++;    // 次數增加準備執行下一次
	}
	printf("        total = %5d\n",total);		//print total score
    return 0;
}
void CMFC_CreatBinaryTreeView::OnDraw(CDC* /*pDC*/)
{
	CMFC_CreatBinaryTreeDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;
	// TODO:  在此处为本机数据添加绘制代码

	CreatBinaryTreeDlg dlg;	//创建对话框类对象
	dlg.DoModal();
	//CString转换为wchar_t*
	wchar_t *VLR = dlg.PreBinTree.GetBuffer();
	dlg.PreBinTree.ReleaseBuffer();
	wchar_t *LVR = dlg.MidBinTree.GetBuffer();
	dlg.MidBinTree.ReleaseBuffer();


	int N = dlg.PreBinTree.GetLength();	  //前序序列的长度,二叉树结点个数
	int len = dlg.MidBinTree.GetLength();	//中序序列的长度
	if (N != len)
	{
		INT_PTR Respon;
		Respon = MessageBox(_T("前序和中序序列输入错误,退出!"), _T("错误提示"), MB_OK | MB_ICONSTOP);
		return;
	}

	//将对话框中的输入数据传入创建二叉树的模板类的构造函数中构造二叉树
	CBinaryTree<wchar_t> BinTree(VLR, LVR, N);
	BinTreeNode<wchar_t> *Root = BinTree.GetRoot();		//获取二叉树的根结点
	int depth = BinTree.Depth(Root);	//二叉树的深度
	Queue<BinTreeNode<wchar_t>*, int, int> Q;	//添加队列,用来存储二叉树的结点,以及结点所显示位置的圆的圆心坐标

	//获取菜单文本的坐标
	CRect Re;
	this->GetWindowRect(Re);
	auto w = Re.Width();
	auto h = Re.Height();
	CClientDC Dc(this);	

	//结点的坐标分布
	int Height = 1;	//结点的高度每增加一层点,高度就加一
	int HeightLeft;	//左孩子结点的高度
	int HeightRight; //右孩子结点的高度
	int R = h / (4 * (depth + 1));	//圆的半径

	int Molecule = 1;	//圆心坐标的分子
	int Denominator;	//圆心坐标的分母
	int X0, Y0;		//包装结点数据的圆的圆心坐标
	int XA, YA, XD, YD;		//圆外接正方形的左上角和右下角端点的坐标
	int XE, YE, XF, YF;		//连接两个圆的线段的端点坐标,点E在点F的上方
	Q.EnQueue(Root, Molecule, Height);

	while (!Q.IsEmpty())
	{
		//将当前结点的相关数据弹出
		Q.DeQueue(Root, Molecule, Height);
		//圆心坐标
		Denominator = (int)pow(2, Height);
		X0 = w*Molecule / Denominator;		//圆心横坐标
		Y0 = h*Height / (depth + 1);		//圆心纵坐标
		
		//正方形的两端点的坐标
		XA = X0 - R;	//正方形左上角端点坐标
		YA = Y0 - R;
		XD = X0 + R;	//正方形右下角端点坐标
		YD = Y0 + R;
		//画圆
		Dc.Ellipse(XA, YA, XD, YD);

		//在圆心显示二叉树的根结点数据
		CString da;
		da += Root->data;   
		Dc.SetTextColor(RGB(255, 0, 0));	//设置输出文本颜色为红色
		Dc.TextOutW(X0, Y0, da);

		if (Root->LeftChild)
		{
			//如果有左孩子,就画左线段
			//线段的上端点坐标
			XE = (int)(X0 - R / sqrt(2));		//XO为当前结点的圆心横坐标
			YE = (int)(Y0 + R / sqrt(2));		//YO为当前结点的圆心纵坐标

			HeightLeft = Height + 1;	//高度加一
			Molecule = 2 * Molecule - 1;	//左为减,左子女的圆心横坐标的分子
			//线段的下端点坐标
			XF = w*Molecule / (2 * Denominator);
			YF = h*HeightLeft / (depth + 1) -R;		
			//画左线段
			Dc.MoveTo(CPoint(XE, YE));
			Dc.LineTo(CPoint(XF, YF));
			
			//将访问左子女所需要的数据压入队列
			Q.EnQueue(Root->LeftChild, Molecule, HeightLeft);
			Molecule = (Molecule + 1) / 2;	//将跟结点圆心的分子还原
		}
		if (Root->RightChild)
		{
			//如果有右孩子,就画右线段
			//线段的上端点坐标
			XE = (int)(X0 + R / sqrt(2));		//XO为当前结点的圆心横坐标
			YE = (int)(Y0 + R / sqrt(2));		//YO为当前结点的圆心纵坐标

			HeightRight = Height + 1;	//高度加一
			Molecule = 2 * Molecule + 1;	//右为加,右子女的圆心横坐标的分子
			//线段的下端点坐标
			XF = w*Molecule / (2 * Denominator);
			YF = h*HeightRight / (depth + 1) - R;	
			//画右线段
			Dc.MoveTo(CPoint(XE, YE));
			Dc.LineTo(CPoint(XF, YF));

			//将访问右子女所需要的数据压入队列
			Q.EnQueue(Root->RightChild, Molecule, HeightRight);
		}
	}
	ReleaseDC(&Dc);
}