Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void* graphSCCGraphRec(void* gra)
- {
- GraphObject* graph = (GraphObject*)gra;
- //creo lo stack
- StackType* stkType = ConstructStackVecType();
- StackObject* stack = stkConstruct(stkType);
- StackObject* stackRet = stkConstruct(stkType);
- DataType* intDataType = ConstructIntDataType();
- DataObject* bstData = adtConstruct(intDataType);
- BSTType* bstType = ConstructBSTRecursive();
- BSTObject* tree = bstConstruct(bstType);
- BSTObject* treeGreys = bstConstruct(bstType);
- ITRObject* vertItr = graphVertices(graph);
- while(vertItr != NULL && !itrTerminated(vertItr)){
- DataObject* name = itrElement(vertItr);
- int id = adtGetVertexId(name->value);
- adtSetValue(bstData, &id);
- if(!bstExists(tree, bstData)){
- stack = TopologicalRec(graph, id, tree, treeGreys, stack);
- //stack = SCCUtilityRec(graph, id, tree, stack);
- }
- itrSuccessor(vertItr);
- }
- //costruisco il trasposto
- GraphObject* transpose = graphTranspose(graph);
- ITRObject* transpVertItr = graphVertices(transpose);
- //pulisco l'albero dei colori
- bstClear(tree);
- printf("\n*** procedo a stampare lo stack ***\n");
- stkMap(stack, &stampaMap, NULL);
- while(!stkEmpty(stack)){
- uint stackElem = *((int*)adtGetValue(stkTopNPop(stack)));
- adtSetValue(bstData, &stackElem);
- if(!bstExists(tree, bstData)) {
- stkPush(stackRet, bstData);
- DFSVisitSCC(transpose, stackElem, tree);
- }
- }
- printf("\n*** procedo a stampare lo stackRet ***\n");
- stkMap(stackRet, &stampaMap, NULL);
- }
- void* SCCUtilityRec(GraphObject* graph, uint name, BSTObject* tree, StackObject* stack)
- {
- DataType* intDataType = ConstructIntDataType();
- DataObject* intDo = adtConstruct(intDataType);
- ITRObject* edgItr = graphVertexEdges(graph,name);
- adtSetValue(intDo, &name);
- bstInsert(tree ,intDo);
- if(!stkExists(stack,intDo)) {
- stkPush(stack, intDo);
- }
- while(edgItr != NULL && !itrTerminated(edgItr)){
- uint curr = *((int*)itrElement(edgItr));
- adtSetValue(intDo, &curr);
- if(!bstExists(tree, intDo)){
- stack = SCCUtilityRec(graph , curr, tree, stack);
- }
- itrSuccessor(edgItr);
- }
- return stack;
- }
- void DFSVisitSCC(GraphObject* transpose, int stackElem, BSTObject* tree)
- {
- DataType* intDataType = ConstructIntDataType();
- DataObject* intDo = adtConstruct(intDataType);
- ITRObject* edgItr = graphVertexEdges(transpose,stackElem);
- adtSetValue(intDo, &stackElem);
- bstInsert(tree ,intDo);
- while(edgItr != NULL && !itrTerminated(edgItr)){
- uint curr = *((int*)itrElement(edgItr));
- adtSetValue(intDo, &curr);
- if(!bstExists(tree, intDo)){
- DFSVisitSCC(transpose,curr, tree);
- }
- itrSuccessor(edgItr);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement