示例#1
0
int bipartGraphDeleteVertex(bpGraph_t* pGraph, int vertId, int partite)
{
    binTreeNode_t *pDelNode;
    binTreeNode_t **parentNode = (binTreeNode_t**)safeMalloc(sizeof(binTreeNode_t*));
    int *pLeftChild = (int *)safeMalloc(sizeof(int));

	if(partite==1){
        pDelNode = searchDeleteNode(*pGraph->vertices1, vertId, parentNode, pLeftChild);

        /* Delete the vertex from tree */
        deleteTreeNode(pGraph->vertices1,pDelNode,*parentNode,*pLeftChild);

        findAndDelete(*pGraph->vertices2, vertId);

        return FOUND;
	}
	else if(partite==2){
        pDelNode = searchDeleteNode(*pGraph->vertices2, vertId, parentNode, pLeftChild);

        /* Delete the vertex from tree */
        deleteTreeNode(pGraph->vertices2,pDelNode,*parentNode,*pLeftChild);

        findAndDelete(*pGraph->vertices1, vertId);

        return FOUND;
	}

	return ERROR_VALUE;
} /* end of bipartGraphDeleteVertex() */
示例#2
0
int bipartGraphDeleteVertex(bpGraph_t* pGraph, int vertId, int partite)
{
	binTreeNode_t *parent, *pNode1 = NULL, *pNode2 = NULL;
	
	if (partite == 1) {
		parent = NULL;
		int leftChild = 0;
		if ((pNode1 = searchDeleteNode(pGraph->vpVertsP1, vertId, &parent, &leftChild)) != NULL) {
			deleteSublistNode(pGraph->vpVertsP2, vertId);
			deleteTreeNode(pGraph->vpVertsP1, pNode1, parent, leftChild);			
			return SUCCESS;
		}
		return FAILED;
	}
	if (partite == 2) {
		parent = NULL;
		int leftChild = 0;
		if ((pNode2 = searchDeleteNode(pGraph->vpVertsP2, vertId, &parent, &leftChild)) != NULL) {
			deleteSublistNode(pGraph->vpVertsP1, vertId);
			deleteTreeNode(pGraph->vpVertsP2, pNode2, parent, leftChild);
			return SUCCESS;
		}
		return FAILED;
	}
} /* end of bipartGraphDeleteVertex() */
示例#3
0
	void deleteTreeNode(TreeNode *& treeNode)
	{
		if (treeNode->left != NULL)
			deleteTreeNode(treeNode->left);
		if(treeNode->right != NULL)
			deleteTreeNode(treeNode->right);
		
		delete treeNode;
	}
示例#4
0
文件: treeTest.c 项目: mohit88/DSA
void test_delete_child_node_of_root_from_tree(){
	Iterator it;
	int _10 = 10,_20 = 20,_30 = 30;
	ASSERT(insertTreeNode(tree, &_10,NULL));
	ASSERT(insertTreeNode(tree, &_20, &_10));
	ASSERT(insertTreeNode(tree, &_30, &_10));
	ASSERT(deleteTreeNode(tree,&_30));
	it = getChildren(tree,&_10);
	ASSERT(&_20 == next(&it));
	ASSERT(NULL == next(&it));
}
JsonEditorMain::JsonEditorMain(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::JsonEditorMain),
    newInsertText(tr("Insert new data")),
    treeViewColumnKey(tr("Node")),
    treeViewColumnValue(tr("Value")),
    treeViewColumnType(tr("Type"))
{
    ui->setupUi(this);
    connect(ui->menuCodeTools, SIGNAL(toggled(bool)), this, SLOT(toggleCodeToolbar(bool)));
    connect(ui->menuFindTools, SIGNAL(toggled(bool)), this, SLOT(toggleFindToolbar(bool)));
    connect(ui->menuFileTools, SIGNAL(toggled(bool)), this, SLOT(toggleFileToolbar(bool)));
    connect(ui->menuEditTools, SIGNAL(toggled(bool)), this, SLOT(toggleEditToolbar(bool)));
    connect(ui->menuRefresh, SIGNAL(triggered()), this, SLOT(refreshJsonTree()));
    connect(ui->menuInsertNode, SIGNAL(triggered()), this, SLOT(insertTreeNode()));
    connect(ui->menuInsertChild, SIGNAL(triggered()), this, SLOT(insertTreeChild()));
    connect(ui->menuDeleteNode, SIGNAL(triggered()), this, SLOT(deleteTreeNode()));
    connect(ui->jsonTree, SIGNAL(clicked(QModelIndex)), this, SLOT(updateActions()));
    connect(ui->menuFormat, SIGNAL(triggered()), this, SLOT(formatCode()));
    connect(ui->menuHelp, SIGNAL(triggered()), this, SLOT(showHelp()));
    connect(ui->jsonTree, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(dataEdit(QModelIndex)));


//    connect(ui->menuNewFile, SIGNAL(triggered()), this, SLOT(newFile()));
    connect(ui->menuOpenFile, SIGNAL(triggered()), this, SLOT(open()));
    connect(ui->menuSaveFile, SIGNAL(triggered()), this, SLOT(save()));
    connect(ui->menuSaveAs, SIGNAL(triggered()), this, SLOT(saveAs()));

    JSHighlighter * highlight = new JSHighlighter(ui->jsonCode->document());

    setCurrentFile("");

    textEdit = ui->jsonCode;
    connect(textEdit->document(), SIGNAL(contentsChanged()),
            this, SLOT(documentWasModified()));
    setUnifiedTitleAndToolBarOnMac(true);

    m_findDialog = new FindDialog(this);
    m_findDialog->setModal(false);
    m_findDialog->setTextEdit(textEdit);

    m_findReplaceDialog = new FindReplaceDialog(this);
    m_findReplaceDialog->setModal(false);
    m_findReplaceDialog->setTextEdit(textEdit);

    connect(ui->menuFind, SIGNAL(triggered()), m_findDialog, SLOT(show()));
    connect(ui->menuReplace, SIGNAL(triggered()), m_findReplaceDialog, SLOT(show()));

//    connect(ui->actionFindNext, SIGNAL(triggered()), m_findDialog, SLOT(findNext()));
//    connect(ui->actionFindPrevious, SIGNAL(triggered()), m_findDialog, SLOT(findPrev()));

    readSettings();
}
示例#6
0
int bipartGraphDeleteVertex(bpGraph_t* graph, int vertId, int partite)
{
   int numVertsHome, isLeftChild;
   char *vertExistsHome;
   binTreeNode_t **adjTreeHome, *adjTreeAway, *toDelete, *parent;

   if (partite == 1)
   {
      numVertsHome = graph->numVertsP1;
      vertExistsHome = graph->vertExistsP1;
      adjTreeHome = &graph->adjTreeP1;
      adjTreeAway = graph->adjTreeP2;
   }
   else if (partite == 2)
   {
      numVertsHome = graph->numVertsP2;
      vertExistsHome = graph->vertExistsP2;
      adjTreeHome = &graph->adjTreeP2;
      adjTreeAway = graph->adjTreeP1;
   }
   else
   {
      return ERROR_VALUE;
   }

   if (vertId >= numVertsHome || !vertExistsHome[vertId])
   {
      return NOT_FOUND;
   }

   /* delete tree node */
   toDelete = searchDeleteNode(*adjTreeHome, vertId, &parent, &isLeftChild);
   deleteTreeNode(adjTreeHome, toDelete, parent, isLeftChild);

   /* remove all edges towards the removed vertex */
   deleteEdgesTo(adjTreeAway, vertId);
   vertExistsHome[vertId] = 0;

   return FOUND;
} /* end of bipartGraphDeleteVertex() */
示例#7
0
文件: treeTest.c 项目: mohit88/DSA
void test_should_not_delete_node_which_is_not_present(){
	int _10 = 10,_20 = 20;
	ASSERT(insertTreeNode(tree, &_10,NULL));
	ASSERT(0 == deleteTreeNode(tree,&_20));
}
示例#8
0
文件: treeTest.c 项目: mohit88/DSA
void test_should_not_delete_node_having_children(){
	int _10 = 10,_20 = 20;
	ASSERT(insertTreeNode(tree, &_10,NULL));
	ASSERT(insertTreeNode(tree, &_20, &_10));
	ASSERT(0 == deleteTreeNode(tree,&_10));
}
示例#9
0
	void deleteTree(Tree *& tree)
	{
		if(tree->root != NULL)
			deleteTreeNode(tree->root);
	}
示例#10
0
/*
 * Delete the first node found with key.
 */
void deleteTreeNode(binTreeNode_t **ppTree, binTreeNode_t *pDelNode, binTreeNode_t *pDelParent, int bLeftChild)
{
	binTreeNode_t *leftChild, *rightChild;
	binTreeNode_t *pSmallest = NULL, *pSmallestParent = NULL;
	int bSmallestLeftChild = 0;

	if (pDelNode != NULL) {
		/* remove node then update subtrees */
		leftChild = pDelNode->left;
		rightChild = pDelNode->right;


		/* update */
		/* no children */
		if (leftChild == NULL && rightChild == NULL) {
			/* root node to be deleted */
			if (pDelNode == *ppTree) {
				destroyTreeNode(pDelNode);
				*ppTree = NULL;
			}
			/* not root node, so can just deallocate memory */
			else {
				destroyTreeNode(pDelNode);
				if (bLeftChild) {
					pDelParent->left = NULL;
				}
				else {
					pDelParent->right = NULL;
				}
			}
		}
		/* two children */
		else if (leftChild != NULL && rightChild != NULL) {
			pSmallest = findSmallest(rightChild, &pSmallestParent, &bSmallestLeftChild);
			/* exchange pSmallest with deleted node */
			swapNodes(ppTree, pDelNode, &pDelParent, &bLeftChild, pSmallest, &pSmallestParent, &bSmallestLeftChild);
			/* delete the pDelNode now */
			deleteTreeNode(ppTree, pDelNode, pDelParent, bLeftChild);
		}
		/* one child */
		else if (leftChild != NULL) {
			assert(rightChild == NULL);
			/* root node to be deleted */
			if (pDelNode == *ppTree) {
				destroyTreeNode(pDelNode);
				pDelNode = NULL;
				*ppTree = leftChild;
			}
			/* not root node */
			else {
				destroyTreeNode(pDelNode);
				if (bLeftChild) {
					pDelParent->left = leftChild;
				}
				else {
					pDelParent->right = leftChild;
				}
			}
		}
		else if (rightChild != NULL) {
			assert(leftChild == NULL);
			/* root node to be deleted */
			if (pDelNode == *ppTree) {
				destroyTreeNode(pDelNode);
				pDelNode = NULL;
				*ppTree = rightChild;
			}
			/* not root node */
			else {
				destroyTreeNode(pDelNode);
				if (bLeftChild) {
					pDelParent->left = rightChild;
				}
				else {
					pDelParent->right = rightChild;
				}
			}
		}
	}

} /* end of deleteNode() */