Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void DFS_VISIT_PREORDER(vertici* Arr_Vertex,iter_vertex* V,iter_edge* V_ADJ,MapFun mapper){
- uint j;
- int indice_adj;
- int nome_adj;
- int indice_V=search_vertex(Arr_Vertex,V->nome,0,Arr_Vertex->num_vertici);
- V->colore=3;
- mapper(Arr_Vertex->vertice[indice_V]->elem,NULL);
- if(V_ADJ!=NULL) {
- for (j = 0; j < V_ADJ->num_edge; j++) {
- nome_adj = V_ADJ->edge[j];
- indice_adj = search_vertex(Arr_Vertex, nome_adj, 0, Arr_Vertex->num_vertici);
- if (Arr_Vertex->vertice[indice_adj]->colore == 1) {
- DFS_VISIT_PREORDER(Arr_Vertex, Arr_Vertex->vertice[indice_adj], Arr_Vertex->adj[indice_adj],mapper);
- }
- }
- }
- }
- void DFS_VISIT_PREORDER2(vertici* Arr_Vertex,iter_vertex* V,iter_edge* V_ADJ,FoldFun folder,void* elem){
- uint j;
- int indice_adj;
- int nome_adj;
- int indice_V=search_vertex(Arr_Vertex,V->nome,0,Arr_Vertex->num_vertici);
- V->colore=3;
- folder(Arr_Vertex->vertice[indice_V]->elem,elem,NULL);
- if(V_ADJ!=NULL) {
- for (j = 0; j < V_ADJ->num_edge; j++) {
- nome_adj = V_ADJ->edge[j];
- indice_adj = search_vertex(Arr_Vertex, nome_adj, 0, Arr_Vertex->num_vertici);
- if (Arr_Vertex->vertice[indice_adj]->colore == 1) {
- DFS_VISIT_PREORDER2(Arr_Vertex, Arr_Vertex->vertice[indice_adj], Arr_Vertex->adj[indice_adj],folder,elem);
- }
- }
- }
- }
- void DFS_VISIT_POSTORDER(vertici* Arr_Vertex,iter_vertex* V,iter_edge* V_ADJ,MapFun mapper){
- uint j;
- int indice_adj;
- int nome_adj;
- int indice_V=search_vertex(Arr_Vertex,V->nome,0,Arr_Vertex->num_vertici);
- V->colore=2;
- if(V_ADJ!=NULL) {
- for (j = 0; j < V_ADJ->num_edge; j++) {
- nome_adj = V_ADJ->edge[j];
- indice_adj = search_vertex(Arr_Vertex, nome_adj, 0, Arr_Vertex->num_vertici);
- if (Arr_Vertex->vertice[indice_adj]->colore == 1) {
- DFS_VISIT_POSTORDER(Arr_Vertex, Arr_Vertex->vertice[indice_adj], Arr_Vertex->adj[indice_adj],mapper);
- }
- }
- }
- mapper(Arr_Vertex->vertice[indice_V]->elem,NULL);
- V->colore=3;
- }
- void DFS_VISIT_POSTORDER2(vertici* Arr_Vertex,iter_vertex* V,iter_edge* V_ADJ,FoldFun folder,void* elem){
- uint j;
- int indice_adj;
- int nome_adj;
- int indice_V=search_vertex(Arr_Vertex,V->nome,0,Arr_Vertex->num_vertici);
- V->colore=2;
- if(V_ADJ!=NULL) {
- for (j = 0; j < V_ADJ->num_edge; j++) {
- nome_adj = V_ADJ->edge[j];
- indice_adj = search_vertex(Arr_Vertex, nome_adj, 0, Arr_Vertex->num_vertici);
- if (Arr_Vertex->vertice[indice_adj]->colore == 1) {
- DFS_VISIT_POSTORDER2(Arr_Vertex, Arr_Vertex->vertice[indice_adj], Arr_Vertex->adj[indice_adj],folder,elem);
- }
- }
- }
- V->colore=3;
- folder(Arr_Vertex->vertice[indice_V]->elem,elem,NULL);
- }
- void BFS_VISIT(vertici* Arr_Vertex,QueueObject* queue,MapFun mapper){
- if(queEmpty(queue))return;
- long long int temp;
- temp=(*(long long int*)adtGetValue(queHeadNDequeue(queue)));
- int i;
- int j;
- int nome_adj;
- int indice_adj;
- DataType* type=ConstructIntDataType();
- DataObject* oggetto=adtConstruct(type);
- j=search_vertex(Arr_Vertex,temp,0,Arr_Vertex->num_vertici);
- if(Arr_Vertex->adj[j]!=NULL) {
- for (i = 0; i < Arr_Vertex->adj[j]->num_edge; i++) {
- nome_adj = Arr_Vertex->adj[j]->edge[i];
- indice_adj = search_vertex(Arr_Vertex, nome_adj, 0, Arr_Vertex->num_vertici);
- if (Arr_Vertex->vertice[indice_adj]->colore == 1) {
- Arr_Vertex->vertice[indice_adj]->colore = 3;
- mapper(Arr_Vertex->vertice[indice_adj]->elem,NULL);
- adtSetValue(oggetto, &nome_adj);
- queEnqueue(queue, oggetto);
- }
- }
- }
- BFS_VISIT(Arr_Vertex,queue,mapper);
- }
- void BFS_VISIT2(vertici* Arr_Vertex,QueueObject* queue,FoldFun folder,void* elem){
- if(queEmpty(queue))return;
- long long int temp;
- temp=(*(long long int*)adtGetValue(queHeadNDequeue(queue)));
- int i;
- int j;
- int nome_adj;
- int indice_adj;
- DataType* type=ConstructIntDataType();
- DataObject* oggetto=adtConstruct(type);
- j=search_vertex(Arr_Vertex,temp,0,Arr_Vertex->num_vertici);
- if(Arr_Vertex->adj[j]!=NULL) {
- for (i = 0; i < Arr_Vertex->adj[j]->num_edge; i++) {
- nome_adj = Arr_Vertex->adj[j]->edge[i];
- indice_adj = search_vertex(Arr_Vertex, nome_adj, 0, Arr_Vertex->num_vertici);
- if (Arr_Vertex->vertice[indice_adj]->colore == 1) {
- Arr_Vertex->vertice[indice_adj]->colore = 3;
- folder(Arr_Vertex->vertice[indice_adj]->elem,elem,NULL);
- adtSetValue(oggetto, &nome_adj);
- queEnqueue(queue, oggetto);
- }
- }
- }
- BFS_VISIT2(Arr_Vertex,queue,folder,elem);
- }
- 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){
- uint j;
- int i;
- int indice_adj;
- int nome_adj;
- int indice_V=search_vertex(Arr_Vertex,V->nome,0,Arr_Vertex->num_vertici);
- V->colore=3;
- if(V->nome!=rapp_att){
- for(i=0;i<max_SCC;i++){
- if(V->nome==lista_SCC[i]){
- graphInsertEdge(SCC,rapp_att,V->nome);
- return;
- }
- }
- }
- if(V_ADJ!=NULL) {
- for (j = 0; j < V_ADJ->num_edge; j++) {
- nome_adj = V_ADJ->edge[j];
- indice_adj = search_vertex(Arr_Vertex, nome_adj, 0, Arr_Vertex->num_vertici);
- if (Arr_Vertex->vertice[indice_adj]->colore == 1) {
- DFS_VISIT_SCC3(Arr_Vertex, Arr_Vertex->vertice[indice_adj], Arr_Vertex->adj[indice_adj],SCC,lista_SCC,rapp_att,max_SCC);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement