Esempio n. 1
0
File: maintest.c Progetto: wanglf/ds
int 
main()
{
	/*int treeCount = GetSubnetCount();*/
	switchADT swList[swCount];
	int actualCount = GetSWListFromFile("switch.ini", swList, swCount);
	PtrToTreeNode *trees = malloc(sizeof(PtrToTreeNode) * actualCount);

	int i;
	for (i = 0; i < actualCount; i++) {
		trees[i] = NewTreeNode();
		SetTreeElement(trees[i], swList[i]);
		if (swList[i] -> fatherIndex != -1) {
			AddFirstChild(trees[i], trees[swList[i] -> fatherIndex]);
		}

		if (swList[i] -> leftIndex != -1) {
			AddBrother(trees[i], trees[swList[i] -> leftIndex]);
		}

	}

	preorder(trees[0], visitSwitch);
	printf("---------------------------------\n");
	postorder(trees[0], visitSwitch);

	return EXIT_SUCCESS;
}
Esempio n. 2
0
int KUiShowWndTree::AddChild(KSHOWWNDNODE *pParent, KSHOWWNDNODE *PChild)
{
    int nResult = FALSE;
    KG_PROCESS_ERROR(pParent && PChild);

    if (pParent->pChildNode) 
    {
        AddBrother(pParent->pChildNode, PChild);
    }
    else
    {
        pParent->pChildNode      = PChild;
        PChild->pParentNode      = pParent;
        PChild->pNextBrotherNode = NULL;
        PChild->pPreBrotherNode  = NULL;
        strcpy(PChild->szParentName, pParent->szName);
    }

    nResult = TRUE;
Exit0:
    return nResult;
}
Esempio n. 3
0
/***
CTreeHandler::~CTreeHandler()
{
	int depthno;
	CTreeLevel** levelarray = 0;
	CTreeLevel* del_level = 0;
	//int levelnum;
	CTreeLevel** curarray = 0;

	if( rootlevel ){
		


	}

	DbgOut( "CTreeHandler : destructor : delete treelevel\n" );

	if( s2e ){
		free( s2e );
		s2e = 0;
	}
	s2e_leng = 0;

	DbgOut( "CTreeHandler : destructor : free s2e\n" );

	if( d2l ){
		// d2l表自体をfree
		for( depthno = 0; depthno < depthmax; depthno++ ){
			curarray = *(d2l + depthno);
			free( curarray );
		}

		free( d2l );
		d2l = 0;
	}

	DbgOut( "CTreeHandler : destructor : free d2l\n" );

	if( d2lnum ){
		free( d2lnum );
		d2lnum = 0;
	}
	depthmax = 0;

	DbgOut( "CTreeHandler : destructor : free d2lnum\n" );
}
***/
int CTreeHandler::AddTree( char* srcname, int srcserino )
{
		//serialno を返す。
		//no2ele, depth2ele へのセット
		//modeによって、同一nameへの対応を変える。
		//SetChain もする。
		//import時はserialnoを呼び出し側で指定。export時はallocate番号を自動的にセット。
	int ret;

	CTreeElem* parelem = 0;
	CTreeElem* befelem = 0;

	if( (mode & TMODE_IMPORT) && (srcserino < 0) ){
		DbgOut( "CTreeHandler : AddTree : serialno error %d !!!\n", srcserino );
		return -1;
	}
	
	// TMODE_MULT以外は 名前チェック
	if( mode & TMODE_ONCE ){
		// 全ての名前をチェックして、すでにあったら アウト
		ret = Find( srcname );
		if( ret ){
			DbgOut( "CTreeHandler : AddTree : TMODE_ONCE : name check error !!!\n" );
			return -1;
		}
	}else if( mode & TMODE_LEVEL_ONCE ){
		// 同じLEVELの名前だけチェックして、すでにあったら アウト
		ret = Find( srcname, curdepth );
		if( ret ){
			DbgOut( "CTreeHandler : AddTree : TMODE_LEVEL_ONCE : name check error !!!\n" );
			return -1;
		}
	}

	parelem = (*this)( parseri );
	befelem = (*this)( befseri );
	if( !parelem || !befelem ){
		DbgOut( "CTreeHandler : AddTree : invalid elemno error !!! : parseri %d, befseri %d\n",
			parseri, befseri );
		return -1;
	}

	switch( addtype ){
	case ADDT_DOWN:
		curseri = AddChild( parelem, srcname, curdepth, srcserino );
		//curseri = AddChild( parseri, srcname, curdepth, srcserino );
		DbgOut( "CTreeHandler : AddTree : AddChild :%d %s, parseri %d, curdepth %d\n", 
			curseri, srcname, parseri, curdepth );
		break;
	case ADDT_LEVEL:
		curseri = AddBrother( befelem, srcname, srcserino );
		DbgOut( "CTreeHandler : AddTree : AddBrother : %d %s, parseri %d, curdepth %d\n", 
			curseri, srcname, parseri, curdepth );
		break;

	case ADDT_UP:
	default:
		// error
		curseri = -1;
		break;
	}

	//befaddtype = addtype;
	befseri = curseri;

	_ASSERT( curseri > 0 );
	return curseri;

}