Esempio n. 1
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() */
Esempio n. 2
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() */
Esempio n. 3
0
int bipartGraphInsertEdge(bpGraph_t* pGraph, int srcVertId, int tarVertId, int srcPartite)
{
	/* TODO: Implement me! */
	binTreeNode_t *parent = NULL, *pNode1 = NULL, *pNode2 = NULL, *left = NULL, *right = NULL;
	int leftChild = 0;
	if (srcPartite == 1) {
		if ((pNode1 = searchDeleteNode(pGraph->vpVertsP1, srcVertId, &parent, &leftChild)) != NULL && (pNode2 = searchDeleteNode(pGraph->vpVertsP2, tarVertId, &parent, &leftChild)) != NULL) {
			if (!findElement(pNode1->value, tarVertId)) {
				addNode(pNode1->value, tarVertId);
				return NEW_EDGE;
			} else {
				return EXISTING_EDGE;
			}
		}        
		return ERROR_VALUE;
	}
	else if (srcPartite == 2) {
        if ((pNode2 = searchDeleteNode(pGraph->vpVertsP2, srcVertId, &parent, &leftChild)) != NULL && (pNode1 = searchDeleteNode(pGraph->vpVertsP1, tarVertId, &parent, &leftChild)) != NULL) {
			if (!findElement(pNode2->value, tarVertId)) {
				addNode(pNode2->value, tarVertId);
				return NEW_EDGE;
			} else {
				return EXISTING_EDGE;
			}
		}        
		return ERROR_VALUE;
	}
	return ERROR_VALUE;
	/* TODO: Replace placeholder. */
} /* end of bipartGraphInsertEdge() */
Esempio n. 4
0
int bipartGraphFindEdge(bpGraph_t* pGraph, int srcVertId, int tarVertId, int srcPartite)
{
	/** TODO: Implement me! */
	binTreeNode_t *parent = NULL, *pNode1 = NULL, *pNode2 = NULL;
	int leftChild = 0;
	if (srcPartite == 1) {
		if ((pNode1 = searchDeleteNode(pGraph->vpVertsP1, srcVertId, &parent, &leftChild)) != NULL) {
			return findElement(pNode1->value, tarVertId);
		}
		return NOT_FOUND;
	}
	if (srcPartite == 2) {
		if ((pNode2 = searchDeleteNode(pGraph->vpVertsP2, srcVertId, &parent, &leftChild)) != NULL) {
			return findElement(pNode2->value, tarVertId);
		}
		return NOT_FOUND;
	}
	return ERROR_VALUE;
} /* end of bipartGraphFindEdge() */
Esempio n. 5
0
int bipartGraphDeleteEdge(bpGraph_t* pGraph,  int srcVertId, int tarVertId, int srcPartite)
{
	int errorStatus;
    binTreeNode_t *pNode = NULL, *left = NULL, *right = NULL, *parent=NULL;
    int leftChild = 0;
	if (srcPartite == 1) {
        if ((pNode = searchDeleteNode(pGraph->vpVertsP1, srcVertId, &parent, &leftChild)) != NULL) {
        	return deleteNode(pNode->value, tarVertId);
        } else {
        	return NOT_FOUND;
        }        
	}
	else if (srcPartite == 2) {
        if ((pNode = searchDeleteNode(pGraph->vpVertsP2, srcVertId, &parent, &leftChild)) != NULL) {
        	return deleteNode(pNode->value, tarVertId);
        } else {
        	return NOT_FOUND;
        }        
	}

	return ERROR_VALUE;

} /** end of bipartGraphDeleteEdge() */
Esempio n. 6
0
int bipartGraphFindVertex(bpGraph_t *pGraph, int vertId, int partite)
{
	/* TODO: Implement me! */

	/* TODO: Replace placeholder. */
	binTreeNode_t *parent = NULL;
	int leftChild = 0;
	if (partite == 1) {
		if (searchDeleteNode(pGraph->vpVertsP1, vertId, &parent, &leftChild) != NULL) {
			return FOUND;
		} else {
			return NOT_FOUND;
		}
	}

	if (partite == 2) {
		if (searchDeleteNode(pGraph->vpVertsP2, vertId, &parent, &leftChild) != NULL) {
			return FOUND;
		} else {
			return NOT_FOUND;
		}
	}
	return ERROR_VALUE;
} /* end of bipartGraphFindVertex() */
Esempio n. 7
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() */