예제 #1
0
void ReOrder(SearchTree T)//对二叉树的重新排布 
{	
	if(T==null)
	{
		return;
	}
		
	else
	{
		Tree = Insert(T->Element,Tree);//通过递归把被破坏的二叉树的元素重新插入到全局变量Tree 
		if(T->Left!=null)
			ReOrder(T->Left);
		if(T->Right!=null)
			ReOrder(T->Right);
	}
}
예제 #2
0
SearchTree Delete(int X,SearchTree T)//删除后要调整高度,各种判断条件太麻烦了,所以删完遍历一遍,然后重新插入一遍就OK 
{
	SearchTree ReOrderTree;
	Position Tem;
	
	if(T==null)
		printf("树中没有%d元素",X);
	else if(X<T->Element)
		{
			T->Left = Delete(X,T->Left);
		}
		
		 else if(X>T->Element)
			 {
			 	T->Right = Delete(X,T->Right);
			 }
		 			 	  
		 	  else if(T->Left&&T->Right)//分两种情况:T有两子孩子,有一个或零个孩子 
		 	  		{
		 	  			Tem = FindMin(T->Right);
		 	  			T = Tem;
						T->Right = Delete(Tem->Element,T->Right); 						
		 	  		}
		 	  		else //一个或零个孩子 ,这种情况不需要重新排列。 
		 	  		{
		 	  			Tem = T;
		 	  			if(T->Left==null)
		 	  				T=T->Right;
		 	  			else if(T->Right==null)
		 	  				T=T->Left;
		 	  			free(Tem);
		 	  		}	
	//	T->Height=Max(Height(T->Left),Height(T->Right))+1;
		Tree = null;
		ReOrder(T);
		ReOrderTree=Tree;
		Tree = null;
	   return ReOrderTree;
}	
예제 #3
0
BOOL CXTPTabManager::PerformClick(HWND hWnd, CPoint pt, BOOL bNoItemClick)
{
	CXTPTabManagerNavigateButton* pNavigateButton = HitTestNavigateButton(pt, FALSE);
	if (pNavigateButton)
	{
		pNavigateButton->PerformClick(hWnd, pt);
		return TRUE;
	}

	if (bNoItemClick)
		return FALSE;

	CXTPTabManagerItem* pItem = HitTest(pt);

	if (pItem)
	{
		if (!OnBeforeItemClick(pItem))
			return FALSE;

		if (IsAllowReorder())
		{
			ReOrder(hWnd, pt, pItem);
		}
		else if (GetPaintManager()->m_bSelectOnButtonDown)
		{
			OnItemClick(pItem);
		}
		else
		{
			TrackClick(hWnd, pt, pItem);
		}
		return TRUE;
	}

	return FALSE;
}
예제 #4
0
void
update_contig_order(Tcl_Interp *interp,
		    GapIO *io,
		    int cs_id,
		    int *contig_array,
		    int num_contigs,
		    int cx)
{
    GCardinal *order = ArrayBase(GCardinal, io->contig_order);
    obj_cs *cs;
    int i, j;
    double wx, wy;
    int left_position;
    char cmd[1024];
    int orig_pos = 0;
    reg_buffer_start rs;
    reg_buffer_end re;
    reg_order ro;

    cs = result_data(io, cs_id, 0);

    CanvasToWorld(cs->canvas, cx, 0, &wx, &wy);

    /*
     * returns the nth contig to the left of the wx, NOT the contig number.
     * If this is to the left of the first contig, returns 0.
     */
    left_position = find_left_position(io, order, wx);

    for (i = 0; i < NumContigs(io); i++) {
	if (order[i] == contig_array[0]) {
	    orig_pos = i+1;
	    break;
	}
    }

    /* convert index on order to index on contig num */
    for (i = 0; i < num_contigs; i++) {

	for (j = 0; j < NumContigs(io); j++) {
	    if (order[j] == contig_array[i])
		break;
	}
	ReOrder(io, order, j, left_position);

	if (j > left_position) {
	    left_position++;
	    orig_pos++;
	}
    }

    ro.job = REG_ORDER;
    ro.pos = left_position;

#ifdef HACK
    /* HACK is there a better way of representing this - only need to
     * replot once
     */
    contig_notify(io, 1, (reg_data *)&ro);
#endif

    /* Notify of the start of the flurry of updates */
    rs.job = REG_BUFFER_START;
    for (i = 0; i < num_contigs; i++) {
	contig_notify(io, contig_array[i], (reg_data *)&rs);
    }

    ro.job = REG_ORDER;
    ro.pos = left_position;

    for (i = 0; i< num_contigs; i++)
	contig_notify(io, contig_array[i], (reg_data *)&ro);

    /* Notify the end of our updates */
    re.job = REG_BUFFER_END;
    for (i = 0; i < num_contigs; i++) {
	contig_notify(io, contig_array[i], (reg_data *)&re);
    }

    /* draw larger separator tick to show where contig was moved from */
    sprintf(cmd, "HighlightSeparator %s %d", cs->hori, orig_pos);
    Tcl_Eval(interp, cmd);
}