Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.86 KB | None | 0 0
  1. void DFS_VISIT_PREORDER(vertici* Arr_Vertex,iter_vertex* V,iter_edge* V_ADJ,MapFun mapper){
  2.     uint j;
  3.     int indice_adj;
  4.     int nome_adj;
  5.     int indice_V=search_vertex(Arr_Vertex,V->nome,0,Arr_Vertex->num_vertici);
  6.     V->colore=3;
  7.     mapper(Arr_Vertex->vertice[indice_V]->elem,NULL);
  8.     if(V_ADJ!=NULL) {
  9.         for (j = 0; j < V_ADJ->num_edge; j++) {
  10.             nome_adj = V_ADJ->edge[j];
  11.             indice_adj = search_vertex(Arr_Vertex, nome_adj, 0, Arr_Vertex->num_vertici);
  12.             if (Arr_Vertex->vertice[indice_adj]->colore == 1) {
  13.                 DFS_VISIT_PREORDER(Arr_Vertex, Arr_Vertex->vertice[indice_adj], Arr_Vertex->adj[indice_adj],mapper);
  14.             }
  15.         }
  16.     }
  17. }
  18.  
  19. void DFS_VISIT_PREORDER2(vertici* Arr_Vertex,iter_vertex* V,iter_edge* V_ADJ,FoldFun folder,void* elem){
  20.     uint j;
  21.     int indice_adj;
  22.     int nome_adj;
  23.     int indice_V=search_vertex(Arr_Vertex,V->nome,0,Arr_Vertex->num_vertici);
  24.     V->colore=3;
  25.     folder(Arr_Vertex->vertice[indice_V]->elem,elem,NULL);
  26.     if(V_ADJ!=NULL) {
  27.         for (j = 0; j < V_ADJ->num_edge; j++) {
  28.             nome_adj = V_ADJ->edge[j];
  29.             indice_adj = search_vertex(Arr_Vertex, nome_adj, 0, Arr_Vertex->num_vertici);
  30.             if (Arr_Vertex->vertice[indice_adj]->colore == 1) {
  31.                 DFS_VISIT_PREORDER2(Arr_Vertex, Arr_Vertex->vertice[indice_adj], Arr_Vertex->adj[indice_adj],folder,elem);
  32.             }
  33.         }
  34.     }
  35. }
  36.  
  37. void DFS_VISIT_POSTORDER(vertici* Arr_Vertex,iter_vertex* V,iter_edge* V_ADJ,MapFun mapper){
  38.     uint j;
  39.     int indice_adj;
  40.     int nome_adj;
  41.     int indice_V=search_vertex(Arr_Vertex,V->nome,0,Arr_Vertex->num_vertici);
  42.     V->colore=2;
  43.     if(V_ADJ!=NULL) {
  44.         for (j = 0; j < V_ADJ->num_edge; j++) {
  45.             nome_adj = V_ADJ->edge[j];
  46.             indice_adj = search_vertex(Arr_Vertex, nome_adj, 0, Arr_Vertex->num_vertici);
  47.             if (Arr_Vertex->vertice[indice_adj]->colore == 1) {
  48.                 DFS_VISIT_POSTORDER(Arr_Vertex, Arr_Vertex->vertice[indice_adj], Arr_Vertex->adj[indice_adj],mapper);
  49.             }
  50.         }
  51.     }
  52.     mapper(Arr_Vertex->vertice[indice_V]->elem,NULL);
  53.     V->colore=3;
  54. }
  55.  
  56. void DFS_VISIT_POSTORDER2(vertici* Arr_Vertex,iter_vertex* V,iter_edge* V_ADJ,FoldFun folder,void* elem){
  57.     uint j;
  58.     int indice_adj;
  59.     int nome_adj;
  60.     int indice_V=search_vertex(Arr_Vertex,V->nome,0,Arr_Vertex->num_vertici);
  61.     V->colore=2;
  62.     if(V_ADJ!=NULL) {
  63.         for (j = 0; j < V_ADJ->num_edge; j++) {
  64.             nome_adj = V_ADJ->edge[j];
  65.             indice_adj = search_vertex(Arr_Vertex, nome_adj, 0, Arr_Vertex->num_vertici);
  66.             if (Arr_Vertex->vertice[indice_adj]->colore == 1) {
  67.                 DFS_VISIT_POSTORDER2(Arr_Vertex, Arr_Vertex->vertice[indice_adj], Arr_Vertex->adj[indice_adj],folder,elem);
  68.             }
  69.         }
  70.     }
  71.     V->colore=3;
  72.     folder(Arr_Vertex->vertice[indice_V]->elem,elem,NULL);
  73. }
  74.  
  75. void BFS_VISIT(vertici* Arr_Vertex,QueueObject* queue,MapFun mapper){
  76.     if(queEmpty(queue))return;
  77.     long long int temp;
  78.     temp=(*(long long int*)adtGetValue(queHeadNDequeue(queue)));
  79.     int i;
  80.     int j;
  81.     int nome_adj;
  82.     int indice_adj;
  83.     DataType* type=ConstructIntDataType();
  84.     DataObject* oggetto=adtConstruct(type);
  85.     j=search_vertex(Arr_Vertex,temp,0,Arr_Vertex->num_vertici);
  86.     if(Arr_Vertex->adj[j]!=NULL) {
  87.         for (i = 0; i < Arr_Vertex->adj[j]->num_edge; i++) {
  88.             nome_adj = Arr_Vertex->adj[j]->edge[i];
  89.             indice_adj = search_vertex(Arr_Vertex, nome_adj, 0, Arr_Vertex->num_vertici);
  90.             if (Arr_Vertex->vertice[indice_adj]->colore == 1) {
  91.                 Arr_Vertex->vertice[indice_adj]->colore = 3;
  92.                 mapper(Arr_Vertex->vertice[indice_adj]->elem,NULL);
  93.                 adtSetValue(oggetto, &nome_adj);
  94.                 queEnqueue(queue, oggetto);
  95.             }
  96.         }
  97.     }
  98.     BFS_VISIT(Arr_Vertex,queue,mapper);
  99. }
  100.  
  101. void BFS_VISIT2(vertici* Arr_Vertex,QueueObject* queue,FoldFun folder,void* elem){
  102.     if(queEmpty(queue))return;
  103.     long long int temp;
  104.     temp=(*(long long int*)adtGetValue(queHeadNDequeue(queue)));
  105.     int i;
  106.     int j;
  107.     int nome_adj;
  108.     int indice_adj;
  109.     DataType* type=ConstructIntDataType();
  110.     DataObject* oggetto=adtConstruct(type);
  111.     j=search_vertex(Arr_Vertex,temp,0,Arr_Vertex->num_vertici);
  112.     if(Arr_Vertex->adj[j]!=NULL) {
  113.         for (i = 0; i < Arr_Vertex->adj[j]->num_edge; i++) {
  114.             nome_adj = Arr_Vertex->adj[j]->edge[i];
  115.             indice_adj = search_vertex(Arr_Vertex, nome_adj, 0, Arr_Vertex->num_vertici);
  116.             if (Arr_Vertex->vertice[indice_adj]->colore == 1) {
  117.                 Arr_Vertex->vertice[indice_adj]->colore = 3;
  118.                 folder(Arr_Vertex->vertice[indice_adj]->elem,elem,NULL);
  119.                 adtSetValue(oggetto, &nome_adj);
  120.                 queEnqueue(queue, oggetto);
  121.             }
  122.         }
  123.     }
  124.     BFS_VISIT2(Arr_Vertex,queue,folder,elem);
  125. }
  126.  
  127. void DFS_VISIT_SCC3(vertici* Arr_Vertex,iter_vertex* V,iter_edge* V_ADJ,GraphObject* SCC,int* lista_SCC,int rapp_att,int max_SCC){
  128.     uint j;
  129.     int i;
  130.     int indice_adj;
  131.     int nome_adj;
  132.     int indice_V=search_vertex(Arr_Vertex,V->nome,0,Arr_Vertex->num_vertici);
  133.     V->colore=3;
  134.     if(V->nome!=rapp_att){
  135.         for(i=0;i<max_SCC;i++){
  136.             if(V->nome==lista_SCC[i]){
  137.                 graphInsertEdge(SCC,rapp_att,V->nome);
  138.                 return;
  139.             }
  140.         }
  141.     }
  142.     if(V_ADJ!=NULL) {
  143.         for (j = 0; j < V_ADJ->num_edge; j++) {
  144.             nome_adj = V_ADJ->edge[j];
  145.             indice_adj = search_vertex(Arr_Vertex, nome_adj, 0, Arr_Vertex->num_vertici);
  146.             if (Arr_Vertex->vertice[indice_adj]->colore == 1) {
  147.                 DFS_VISIT_SCC3(Arr_Vertex, Arr_Vertex->vertice[indice_adj], Arr_Vertex->adj[indice_adj],SCC,lista_SCC,rapp_att,max_SCC);
  148.             }
  149.         }
  150.     }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement