int bipartGraphFindEdge(bpGraph_t* pGraph, int srcVertId, int tarVertId, int srcPartite) { binTreeNode_t *pNode; if(srcPartite==1){ /* Searching from the tree */ pNode = searchValue(*pGraph->vertices1, srcVertId); /* Check if vertex exists and has edges */ if(pNode!=NULL && pNode->value!=NULL){ return findElement(pNode->value, tarVertId); } return NOT_FOUND; } else if(srcPartite==2){ /* Searching from the tree */ pNode = searchValue(*pGraph->vertices2, srcVertId); /* Check if vertex exists and has edges */ if(pNode!=NULL && pNode->value!=NULL){ return findElement(pNode->value, tarVertId); } return NOT_FOUND; } return ERROR_VALUE; } /* end of bipartGraphFindEdge() */
int bipartGraphDeleteEdge(bpGraph_t* pGraph, int srcVertId, int tarVertId, int srcPartite) { binTreeNode_t *pNode; int status; if(srcPartite == 1){ pNode = searchValue(*pGraph->vertices1, srcVertId); /* Check if vertex exists and has edges */ if(pNode!=NULL && pNode->value!=NULL){ status = deleteNode(pNode->value, tarVertId); return status; } return NOT_FOUND; } else if(srcPartite==2){ pNode = searchValue(*pGraph->vertices2, srcVertId); /* Check if vertex exists and has edges */ if(pNode!=NULL && pNode->value!=NULL){ status = deleteNode(pNode->value, tarVertId); return status; } return NOT_FOUND; } /* Partite does not exist */ return ERROR_VALUE; } /* end of bipartGraphDeleteEdge() */
int bipartGraphFindVertex(bpGraph_t *pGraph, int vertId, int partite) { binTreeNode_t *pNode; if(partite==1){ /* Searching from the tree */ pNode = searchValue(*pGraph->vertices1, vertId); if(pNode!=NULL){ return FOUND; } return NOT_FOUND; } else if(partite==2){ /* Searching from the tree */ pNode = searchValue(*pGraph->vertices2, vertId); if(pNode!=NULL){ return FOUND; } return NOT_FOUND; } /* Partite does not exist */ return ERROR_VALUE; } /* end of bipartGraphFindVertex() */
int bipartGraphInsertVertex(bpGraph_t* pGraph, int vertId, int partite) { int status; binTreeNode_t *vertex; if(partite==1){ vertex=searchValue(*pGraph->vertices1, vertId); /* Check if vertex already exists */ if(vertex==NULL){ if(*pGraph->vertices1==NULL){ *pGraph->vertices1 = createTreeNode(vertId, NULL); return NEW_VERTEX; } else{ /* initialise new node */ binTreeNode_t *newNode = createTreeNode(vertId, NULL); status = insertTreeNode(*pGraph->vertices1,newNode); return status; } } return EXISTING_VERTEX; }else if(partite==2){ vertex=searchValue(*pGraph->vertices2, vertId); /* Check if vertex already exists */ if(vertex==NULL){ if(*pGraph->vertices2==NULL){ *pGraph->vertices2 = createTreeNode(vertId, NULL); return NEW_VERTEX; } else{ /* initialise new node */ binTreeNode_t *newNode = createTreeNode(vertId, NULL); status = insertTreeNode(*pGraph->vertices2,newNode); return status; } } return EXISTING_VERTEX; } return ERROR_VALUE; } /* end of bipartGraphInsertVertex() */
int lineReader(char *line, HashTable *numbers){ int key; int x; if(line[0] == 'i' || line[0] == 'I'){ key = makeKey(&line[2]); x = insertValue(key, numbers); if(x == -1){ printf("duplicate\n"); return 0; }else{ printf("inserted\n"); return 0; } }else if(line[0] == 's' || line[0] == 'S'){ key = makeKey(&line[2]); x = searchValue(key, numbers); if(x == -1){ printf("absent\n"); return 0; }else{ printf("present\n"); return 0; } }else{ printf("error\n"); return 0; } }
int main(int argc, char* argv[]) { #if DEBUG printf("\n>>==============Debug Value Set=================<<\n"); #endif char* file = argv[1]; linkList *newlinkList = readData(file,1); //linkList *newlinkList = readData(file,2); //adding from back addatPosition(newlinkList,10,45); popFront(newlinkList); popBack(newlinkList); popatPosition(newlinkList,7); popwithValue(newlinkList,45); printlinkList(newlinkList); int value_f = 222; int i = searchValue(newlinkList,value_f); #if DEBUG if(i == 1) printf(">>==============Search: Value %d found=================<<\n",value_f); else printf(">>==============Search: Value not found=================<<\n"); #endif cleanlinkList(newlinkList); return 0; }
main() { SkipList_t *list = NULL; char buf[256]; int choice = 0; list = SkipListAlloc( myCmp, myFree ); if ( list == NULL ) { printf( "ERROR: Allocation of skip list failed\n" ); exit(1); } while (1) { displayMenu(); choice = atoi( gets(buf) ); switch( choice ) { case 1 : insertValue( list ); break; case 2 : deleteValue( list ); break; case 3 : searchValue( list ); break; case 4 : getNextValue( list ); break; case 5 : printValue( list ); break; case 6 : clearList( list ); break; case 7: SkipListFree(list); exit(0); default : break; } } exit(0); }
int main(int argc, const char * argv[]) { Node *node1 = initListItem(1); Node *node2 = initListItem(2); Node *node3 = initListItem(3); Node *node4 = initListItem(4); Node *node5 = initListItem(5); Node *newNode = initListItem(6); insertToTheEnd(node1, node2); insertToTheEnd(node1, node3); insertToTheEnd(node1, node4); insertToTheEnd(node1, node5); printf("All values in the list: "); listAll(node1); int valueUserInput; printf("Input the value to find:"); scanf("%d", &valueUserInput); Node *searchResult = searchValue(node1, valueUserInput); if (searchResult == NULL) { printf("%d is not found in this list!\n", valueUserInput); } else { printf("Search result %d found at %p\n", searchResult->value, searchResult); printf("%p\n", node2); } insertToTheEnd(node1, newNode); listAll(node1); removeListItem(node1, node2); listAll(node1); deallocation(node1); return 0; }
int bipartGraphInsertEdge(bpGraph_t* pGraph, int srcVertId, int tarVertId, int srcPartite) { binTreeNode_t *src, *tar; if(srcPartite == 1){ /* Find source and target vertices */ src = searchValue(*pGraph->vertices1, srcVertId); tar = searchValue(*pGraph->vertices2, tarVertId); /* Check if vertices exist */ if(src!=NULL && tar !=NULL){ /* Check if it is the first edge*/ if(src->value==NULL){ /*Initialise list and assign*/ src->value = (linkedList_t*)safeMalloc(sizeof(linkedList_t)); src->value->pHead=NULL; addNode(src->value, tarVertId); return NEW_EDGE; }else{ /*Check if edge already exists*/ if(!findElement(src->value, tarVertId)){ addNode(src->value, tarVertId); return NEW_EDGE; } return EXISTING_EDGE; } } }else if(srcPartite==2){ /* Find source and target vertices */ src = searchValue(*pGraph->vertices2, srcVertId); tar = searchValue(*pGraph->vertices1, tarVertId); /* Check if vertices exist */ if(src!=NULL && tar !=NULL){ /* Check if it is the first edge*/ if(src->value==NULL){ /*Initialise list and assign*/ src->value = (linkedList_t*)safeMalloc(sizeof(linkedList_t)); src->value->pHead=NULL; addNode(src->value, tarVertId); return NEW_EDGE; }else{ /*Check if edge already exists*/ if(!findElement(src->value, tarVertId)){ addNode(src->value, tarVertId); return NEW_EDGE; } return EXISTING_EDGE; } } } /* partite not found */ return ERROR_VALUE; } /* end of bipartGraphInsertEdge() */