示例#1
0
TreeView::TreeView(QWidget *parent) :
    QTreeView(parent)
{

    deleteNodeAction= new QAction("&Delete",this);
    insertNodeAction= new QAction("&insert",this);
    addNodeAction= new QAction("&add node",this);
    debugPaneAction = new QAction("debug",this);
    deleteRootAction= new QAction("&Delete",this);
    insertRootAction= new QAction("&insert",this);
    addRootAction= new QAction("&add Root",this);



    QObject::connect(this->deleteRootAction, SIGNAL(triggered()), this,
                     SLOT(deleteRoot()));
    QObject::connect(this->insertRootAction, SIGNAL(triggered()), this,
                     SLOT(insertRoot()));

    QObject::connect(this->addRootAction, SIGNAL(triggered()), this,
                     SLOT(addRoot()));
    QObject::connect(this->deleteNodeAction, SIGNAL(triggered()), this,
                     SLOT(deleteNode()));
    QObject::connect(this->insertNodeAction, SIGNAL(triggered()), this,
                     SLOT(insertNode()));

    QObject::connect(this->addNodeAction, SIGNAL(triggered()), this,
                     SLOT(addNode()));

    QObject::connect(this->debugPaneAction, SIGNAL(triggered()), this,
                     SLOT(debugNode()));
}
示例#2
0
void main()
{
    int choice = 7;
    Listinit();
    while(1) 
    {
        printf("LinkedList Operations:\n");
        printf("1. Insert Head\n2. Display\n3. Middle\n4. Reverse List\n5. ReverseRecursiveList\n7. Exit\n");
        printf("Enter your choice : ");
        scanf(" %d", &choice);
        switch (choice)
        {
            case 1  :   insertRoot();
            break;
            case 2  :   display();
            break;
            case 3  :   MiddleList();
            break;
            case 4  :   ReverseList();
            break;
            case 5  :   ReverseRecursiveList(&root);
            break;
            default :
            exit(0);
        }
    }
}
示例#3
0
void ConnectivityGraph::setAsReplacement( EdgeIP e, ETForestLevel l ) {
	assert( e->level == l );
	assert( !e->isTree );

	Vertex & u( vertices[e->vxid1] );
	Vertex & v( vertices[e->vxid2] );

	// remove from non-tree list and update weights
	removeNontreeEdge( e.get(), l );

	e->isTree = true;

//	std::cout << "adding edge " << *e << " as replacement, giving " << std::endl;

	for ( int i = 0; i <= l; ++i ) {
	 	// get the previous roots on level l
		ETNode * ru = u.ETvertices[i].loopNode->findRoot();
		ETNode * rv = v.ETvertices[i].loopNode->findRoot();

		assert( ru != rv );

		// remove the previous roots
		removeRoot( ru, i );
		removeRoot( rv, i );

		// add the edge to this level (and the forest)
		ETNode * newroot = addTreeEdge( u, v, e, i );

		// remember the new root
		insertRoot( newroot, i );
	}

//	EulerTourTree::print( u.ETvertices[0].loopNode->findRoot() );
//	std::cout << std::endl;
}
示例#4
0
treeLink insertRoot (treeLink currentLink, Item item) { 

    if (currentLink == emptyTree) {
        return (NEW (item, emptyTree, emptyTree, 1));
    }
    if (less (key (item), key (currentLink->item))) {
        currentLink->left = insertRoot (currentLink->left, item);
        rotRight (currentLink);
    } else if (less (key (currentLink->item), key (item))) {
        currentLink->right = insertRoot (currentLink->right, item);
        rotLeft (currentLink);
    } else {
        currentLink->size--;
    }
    currentLink->size++;
    return (currentLink);
}
示例#5
0
void ConnectivityGraph::deleteEdge( EdgeIP e ) {
//	std::cout << "deleting edge " << *e <<
//			( e->isTree ? " (tree)" : " (nontree)" ) << std::endl;

//	assert( e->count == 0 );

	Vertex & u( vertices[e->vxid1] );
	Vertex & v( vertices[e->vxid2] );
	assert( EulerTourTree::connected( &u.ETvertices[0], &v.ETvertices[0] ) );

	if ( e->isTree ) {
		// cut all forests F_i, for 0 <= i <= level(e)
		for ( ETForestLevel i = e->level; i >= 0; --i ) {
			ETNode * oldroot = e->arcs[i].first->findRoot();
			assert( oldroot == e->arcs[i].second->findRoot() );

			// remove the old root from the forest
			removeRoot( oldroot, i );

			ETNode * r1 = NULL, * r2 = NULL;
			EulerTourTree::cut( e->arcs[i].first, e->arcs[i].second, &r1, &r2 );

#ifdef DEBUG
			ETNode * ru = u.ETvertices[i].loopNode->findRoot();
			ETNode * rv = v.ETvertices[i].loopNode->findRoot();
			assert( ru != rv );
			assert( ru == r1 || ru == r2 );
			assert( rv == r1 || rv == r2 );
#endif

			// put the new roots in the forest
			insertRoot( r1, i );
			insertRoot( r2, i );
		}

		// attempt to find a replacement edge
		for ( ETForestLevel i = e->level; i >= 0; --i ) {
			if ( replaceEdge( *e, i ) ) break;
		}
	}

//	delete e;
}
/*
	* inserts a node at the root
	* ignores the case where n->value == value
*/
TreeNode insertRoot(TreeNode n, int value)
{
	if (n == NULL){
		n = newNode(value);
	}

	else{
		n->nnodes = numNodes(n); // count the nodes
	}

	if (value < n->value){
		n->leftnode = insertRoot(n->leftnode, value);
		n = rotateRight(n);
	}

	if (value > n->value){
		n->rightnode = insertRoot(n->rightnode, value);
		n = rotateLeft(n);
	}
	return n;
}
示例#7
0
//void ConnectivityGraph::insertEdge( VariableID vid, FactorID fid ) {
void ConnectivityGraph::insertEdge( VertexID vxid1, VertexID vxid2 ) {

	assert( vxid1 != vxid2 );

	Vertex & u( vertices[vxid1] );
	Vertex & v( vertices[vxid2] );

	ETNode * ru = u.ETvertices[0].loopNode->findRoot();
	ETNode * rv = v.ETvertices[0].loopNode->findRoot();

	EdgeIP e = edgepool.get();
	e->set( /*vid, fid,*/ vxid1, vxid2, /*0,*/ 0 );

//	std::cout << "inserting/incrementing edge: " << *e << std::endl;


//#ifdef DEBUG
//	assert( !existingEdges[vxid][fxid][fid] );
//	assert( !existingEdges[fxid][vxid][fid] );
//	existingEdges[vxid][fxid].set( fid );
//	existingEdges[fxid][vxid].set( fid );
//#endif // DEBUG

//	if ( e->count == 0 ) {
//		e->set( vid, fid, vxid, fxid, 1, 0 ); // ensure level is 0

//		std::cout << "adding edge to graph: " << *e << std::endl;

		// check if they're already connected
		if ( ru == rv ) {
			// add edge to non-tree adjacency lists and update weights, which
			// correspond to edge counts
			addNontreeEdge( u, v, e, 0 );

		} else {
			e->isTree = true;

			// find and remove the two previous roots from the level 0 forest
			removeRoot( ru, 0 );
			removeRoot( rv, 0 );

			ETNode * newroot = addTreeEdge( u, v, e, 0 );

			// put the new root into the level 0 forest -- note that we use the
			// root's vertex ID as the index
			insertRoot( newroot, 0 );
		}
//	} else {
//		++e->count;
//	}
}
示例#8
0
treeLink insertRandom (treeLink currTree, Item item) {
    Key currKey = key (currTree->item);
    if (currTree == emptyTree) {
        return NEW (item, emptyTree, emptyTree, 1);
    }
    if (rand () < RAND_MAX/(currTree->size+1)) {
        return (insertRoot (currTree, item));
    } else if (less (key (item), currKey)) {
        insertRandom (currTree->left, item);
    } else {
        insertRandom (currTree->right, item);
    }
    currTree->size++;
    return currTree;
} 
示例#9
0
void ConnectivityGraph::raiseTreeEdges( ETNode * n, ETForestLevel l ) {
	assert( n->isLoop() );
	Vertex & u( vertices[n->vx1->vxid] );

	auto & list = u.adjTreeEdges[l];

	while ( !list.empty() ) {
		// get and remove the last edge (efficient in a vector)
		EdgeIP e = list.back();

		assert( e->isTree );
		assert( e->level == l );

//		removeTreeEdge( e.get(), l );

		list.pop_back();

		Vertex & v( e->vxid1 == n->vx1->vxid ? vertices[e->vxid2] :
				vertices[e->vxid1] );

		assert( EulerTourTree::connected( &u.ETvertices[l], &v.ETvertices[l] ) );

		// remove e from v's adjacency lists
		EdgeIP ev = getFromList( e->vxid1, e->vxid2, v.adjTreeEdges[l], l );
		assert( ev == e );

		u.ETvertices[l].loopNode->addWeight( -1, ETWeight::Tree );
		v.ETvertices[l].loopNode->addWeight( -1, ETWeight::Tree );

		// get the previous roots on level l+1
		ETNode * ru = u.ETvertices[l+1].loopNode->findRoot();
		ETNode * rv = v.ETvertices[l+1].loopNode->findRoot();

		assert( ru != rv );

		// remove the previous roots
		removeRoot( ru, l+1 );
		removeRoot( rv, l+1 );

		// move the edge up a level, add it to this new level (and the forest)
		e->level = l + 1;
		ETNode * newroot = addTreeEdge( u, v, e, l+1 );

		// remember the new root
		insertRoot( newroot, l+1 );
	}
}